18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Atheros CARL9170 driver
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * PHY and RF code
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
98c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
108c2ecf20Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
118c2ecf20Sopenharmony_ci * (at your option) any later version.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
148c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
158c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
168c2ecf20Sopenharmony_ci * GNU General Public License for more details.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
198c2ecf20Sopenharmony_ci * along with this program; see the file COPYING.  If not, see
208c2ecf20Sopenharmony_ci * http://www.gnu.org/licenses/.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * This file incorporates work covered by the following copyright and
238c2ecf20Sopenharmony_ci * permission notice:
248c2ecf20Sopenharmony_ci *    Copyright (c) 2007-2008 Atheros Communications, Inc.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *    Permission to use, copy, modify, and/or distribute this software for any
278c2ecf20Sopenharmony_ci *    purpose with or without fee is hereby granted, provided that the above
288c2ecf20Sopenharmony_ci *    copyright notice and this permission notice appear in all copies.
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
318c2ecf20Sopenharmony_ci *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
328c2ecf20Sopenharmony_ci *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
338c2ecf20Sopenharmony_ci *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
348c2ecf20Sopenharmony_ci *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
358c2ecf20Sopenharmony_ci *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
368c2ecf20Sopenharmony_ci *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#include <linux/bitrev.h>
408c2ecf20Sopenharmony_ci#include "carl9170.h"
418c2ecf20Sopenharmony_ci#include "cmd.h"
428c2ecf20Sopenharmony_ci#include "phy.h"
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic int carl9170_init_power_cal(struct ar9170 *ar)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	carl9170_regwrite_begin(ar);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE_MAX, 0x7f);
498c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE1, 0x3f3f3f3f);
508c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE2, 0x3f3f3f3f);
518c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE3, 0x3f3f3f3f);
528c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE4, 0x3f3f3f3f);
538c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE5, 0x3f3f3f3f);
548c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE6, 0x3f3f3f3f);
558c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE7, 0x3f3f3f3f);
568c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE8, 0x3f3f3f3f);
578c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE9, 0x3f3f3f3f);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	carl9170_regwrite_finish();
608c2ecf20Sopenharmony_ci	return carl9170_regwrite_result();
618c2ecf20Sopenharmony_ci}
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct carl9170_phy_init {
648c2ecf20Sopenharmony_ci	u32 reg, _5ghz_20, _5ghz_40, _2ghz_40, _2ghz_20;
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic struct carl9170_phy_init ar5416_phy_init[] = {
688c2ecf20Sopenharmony_ci	{ 0x1c5800, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
698c2ecf20Sopenharmony_ci	{ 0x1c5804, 0x00000300, 0x000003c4, 0x000003c4, 0x00000300, },
708c2ecf20Sopenharmony_ci	{ 0x1c5808, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
718c2ecf20Sopenharmony_ci	{ 0x1c580c, 0xad848e19, 0xad848e19, 0xad848e19, 0xad848e19, },
728c2ecf20Sopenharmony_ci	{ 0x1c5810, 0x7d14e000, 0x7d14e000, 0x7d14e000, 0x7d14e000, },
738c2ecf20Sopenharmony_ci	{ 0x1c5814, 0x9c0a9f6b, 0x9c0a9f6b, 0x9c0a9f6b, 0x9c0a9f6b, },
748c2ecf20Sopenharmony_ci	{ 0x1c5818, 0x00000090, 0x00000090, 0x00000090, 0x00000090, },
758c2ecf20Sopenharmony_ci	{ 0x1c581c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
768c2ecf20Sopenharmony_ci	{ 0x1c5820, 0x02020200, 0x02020200, 0x02020200, 0x02020200, },
778c2ecf20Sopenharmony_ci	{ 0x1c5824, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, },
788c2ecf20Sopenharmony_ci	{ 0x1c5828, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001, },
798c2ecf20Sopenharmony_ci	{ 0x1c582c, 0x0000a000, 0x0000a000, 0x0000a000, 0x0000a000, },
808c2ecf20Sopenharmony_ci	{ 0x1c5830, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
818c2ecf20Sopenharmony_ci	{ 0x1c5834, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, },
828c2ecf20Sopenharmony_ci	{ 0x1c5838, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
838c2ecf20Sopenharmony_ci	{ 0x1c583c, 0x00200400, 0x00200400, 0x00200400, 0x00200400, },
848c2ecf20Sopenharmony_ci	{ 0x1c5840, 0x206a002e, 0x206a002e, 0x206a002e, 0x206a002e, },
858c2ecf20Sopenharmony_ci	{ 0x1c5844, 0x1372161e, 0x13721c1e, 0x13721c24, 0x137216a4, },
868c2ecf20Sopenharmony_ci	{ 0x1c5848, 0x001a6a65, 0x001a6a65, 0x00197a68, 0x00197a68, },
878c2ecf20Sopenharmony_ci	{ 0x1c584c, 0x1284233c, 0x1284233c, 0x1284233c, 0x1284233c, },
888c2ecf20Sopenharmony_ci	{ 0x1c5850, 0x6c48b4e4, 0x6d48b4e4, 0x6d48b0e4, 0x6c48b0e4, },
898c2ecf20Sopenharmony_ci	{ 0x1c5854, 0x00000859, 0x00000859, 0x00000859, 0x00000859, },
908c2ecf20Sopenharmony_ci	{ 0x1c5858, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, },
918c2ecf20Sopenharmony_ci	{ 0x1c585c, 0x31395c5e, 0x3139605e, 0x3139605e, 0x31395c5e, },
928c2ecf20Sopenharmony_ci	{ 0x1c5860, 0x0004dd10, 0x0004dd10, 0x0004dd20, 0x0004dd20, },
938c2ecf20Sopenharmony_ci	{ 0x1c5864, 0x0001c600, 0x0001c600, 0x0001c600, 0x0001c600, },
948c2ecf20Sopenharmony_ci	{ 0x1c5868, 0x409a4190, 0x409a4190, 0x409a4190, 0x409a4190, },
958c2ecf20Sopenharmony_ci	{ 0x1c586c, 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081, },
968c2ecf20Sopenharmony_ci	{ 0x1c5900, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
978c2ecf20Sopenharmony_ci	{ 0x1c5904, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
988c2ecf20Sopenharmony_ci	{ 0x1c5908, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
998c2ecf20Sopenharmony_ci	{ 0x1c590c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1008c2ecf20Sopenharmony_ci	{ 0x1c5914, 0x000007d0, 0x000007d0, 0x00000898, 0x00000898, },
1018c2ecf20Sopenharmony_ci	{ 0x1c5918, 0x00000118, 0x00000230, 0x00000268, 0x00000134, },
1028c2ecf20Sopenharmony_ci	{ 0x1c591c, 0x10000fff, 0x10000fff, 0x10000fff, 0x10000fff, },
1038c2ecf20Sopenharmony_ci	{ 0x1c5920, 0x0510081c, 0x0510081c, 0x0510001c, 0x0510001c, },
1048c2ecf20Sopenharmony_ci	{ 0x1c5924, 0xd0058a15, 0xd0058a15, 0xd0058a15, 0xd0058a15, },
1058c2ecf20Sopenharmony_ci	{ 0x1c5928, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
1068c2ecf20Sopenharmony_ci	{ 0x1c592c, 0x00000004, 0x00000004, 0x00000004, 0x00000004, },
1078c2ecf20Sopenharmony_ci	{ 0x1c5934, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
1088c2ecf20Sopenharmony_ci	{ 0x1c5938, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
1098c2ecf20Sopenharmony_ci	{ 0x1c593c, 0x0000007f, 0x0000007f, 0x0000007f, 0x0000007f, },
1108c2ecf20Sopenharmony_ci	{ 0x1c5944, 0xdfb81020, 0xdfb81020, 0xdfb81020, 0xdfb81020, },
1118c2ecf20Sopenharmony_ci	{ 0x1c5948, 0x9280b212, 0x9280b212, 0x9280b212, 0x9280b212, },
1128c2ecf20Sopenharmony_ci	{ 0x1c594c, 0x00020028, 0x00020028, 0x00020028, 0x00020028, },
1138c2ecf20Sopenharmony_ci	{ 0x1c5954, 0x5d50e188, 0x5d50e188, 0x5d50e188, 0x5d50e188, },
1148c2ecf20Sopenharmony_ci	{ 0x1c5958, 0x00081fff, 0x00081fff, 0x00081fff, 0x00081fff, },
1158c2ecf20Sopenharmony_ci	{ 0x1c5960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
1168c2ecf20Sopenharmony_ci	{ 0x1c5964, 0x00001120, 0x00001120, 0x00001120, 0x00001120, },
1178c2ecf20Sopenharmony_ci	{ 0x1c5970, 0x190fb515, 0x190fb515, 0x190fb515, 0x190fb515, },
1188c2ecf20Sopenharmony_ci	{ 0x1c5974, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1198c2ecf20Sopenharmony_ci	{ 0x1c5978, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
1208c2ecf20Sopenharmony_ci	{ 0x1c597c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1218c2ecf20Sopenharmony_ci	{ 0x1c5980, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1228c2ecf20Sopenharmony_ci	{ 0x1c5984, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1238c2ecf20Sopenharmony_ci	{ 0x1c5988, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1248c2ecf20Sopenharmony_ci	{ 0x1c598c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1258c2ecf20Sopenharmony_ci	{ 0x1c5990, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1268c2ecf20Sopenharmony_ci	{ 0x1c5994, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1278c2ecf20Sopenharmony_ci	{ 0x1c5998, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1288c2ecf20Sopenharmony_ci	{ 0x1c599c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1298c2ecf20Sopenharmony_ci	{ 0x1c59a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1308c2ecf20Sopenharmony_ci	{ 0x1c59a4, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
1318c2ecf20Sopenharmony_ci	{ 0x1c59a8, 0x001fff00, 0x001fff00, 0x001fff00, 0x001fff00, },
1328c2ecf20Sopenharmony_ci	{ 0x1c59ac, 0x006f00c4, 0x006f00c4, 0x006f00c4, 0x006f00c4, },
1338c2ecf20Sopenharmony_ci	{ 0x1c59b0, 0x03051000, 0x03051000, 0x03051000, 0x03051000, },
1348c2ecf20Sopenharmony_ci	{ 0x1c59b4, 0x00000820, 0x00000820, 0x00000820, 0x00000820, },
1358c2ecf20Sopenharmony_ci	{ 0x1c59bc, 0x00181400, 0x00181400, 0x00181400, 0x00181400, },
1368c2ecf20Sopenharmony_ci	{ 0x1c59c0, 0x038919be, 0x038919be, 0x038919be, 0x038919be, },
1378c2ecf20Sopenharmony_ci	{ 0x1c59c4, 0x06336f77, 0x06336f77, 0x06336f77, 0x06336f77, },
1388c2ecf20Sopenharmony_ci	{ 0x1c59c8, 0x6af6532c, 0x6af6532c, 0x6af6532c, 0x6af6532c, },
1398c2ecf20Sopenharmony_ci	{ 0x1c59cc, 0x08f186c8, 0x08f186c8, 0x08f186c8, 0x08f186c8, },
1408c2ecf20Sopenharmony_ci	{ 0x1c59d0, 0x00046384, 0x00046384, 0x00046384, 0x00046384, },
1418c2ecf20Sopenharmony_ci	{ 0x1c59d4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1428c2ecf20Sopenharmony_ci	{ 0x1c59d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1438c2ecf20Sopenharmony_ci	{ 0x1c59dc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1448c2ecf20Sopenharmony_ci	{ 0x1c59e0, 0x00000200, 0x00000200, 0x00000200, 0x00000200, },
1458c2ecf20Sopenharmony_ci	{ 0x1c59e4, 0x64646464, 0x64646464, 0x64646464, 0x64646464, },
1468c2ecf20Sopenharmony_ci	{ 0x1c59e8, 0x3c787878, 0x3c787878, 0x3c787878, 0x3c787878, },
1478c2ecf20Sopenharmony_ci	{ 0x1c59ec, 0x000000aa, 0x000000aa, 0x000000aa, 0x000000aa, },
1488c2ecf20Sopenharmony_ci	{ 0x1c59f0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1498c2ecf20Sopenharmony_ci	{ 0x1c59fc, 0x00001042, 0x00001042, 0x00001042, 0x00001042, },
1508c2ecf20Sopenharmony_ci	{ 0x1c5a00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
1518c2ecf20Sopenharmony_ci	{ 0x1c5a04, 0x00000040, 0x00000040, 0x00000040, 0x00000040, },
1528c2ecf20Sopenharmony_ci	{ 0x1c5a08, 0x00000080, 0x00000080, 0x00000080, 0x00000080, },
1538c2ecf20Sopenharmony_ci	{ 0x1c5a0c, 0x000001a1, 0x000001a1, 0x00000141, 0x00000141, },
1548c2ecf20Sopenharmony_ci	{ 0x1c5a10, 0x000001e1, 0x000001e1, 0x00000181, 0x00000181, },
1558c2ecf20Sopenharmony_ci	{ 0x1c5a14, 0x00000021, 0x00000021, 0x000001c1, 0x000001c1, },
1568c2ecf20Sopenharmony_ci	{ 0x1c5a18, 0x00000061, 0x00000061, 0x00000001, 0x00000001, },
1578c2ecf20Sopenharmony_ci	{ 0x1c5a1c, 0x00000168, 0x00000168, 0x00000041, 0x00000041, },
1588c2ecf20Sopenharmony_ci	{ 0x1c5a20, 0x000001a8, 0x000001a8, 0x000001a8, 0x000001a8, },
1598c2ecf20Sopenharmony_ci	{ 0x1c5a24, 0x000001e8, 0x000001e8, 0x000001e8, 0x000001e8, },
1608c2ecf20Sopenharmony_ci	{ 0x1c5a28, 0x00000028, 0x00000028, 0x00000028, 0x00000028, },
1618c2ecf20Sopenharmony_ci	{ 0x1c5a2c, 0x00000068, 0x00000068, 0x00000068, 0x00000068, },
1628c2ecf20Sopenharmony_ci	{ 0x1c5a30, 0x00000189, 0x00000189, 0x000000a8, 0x000000a8, },
1638c2ecf20Sopenharmony_ci	{ 0x1c5a34, 0x000001c9, 0x000001c9, 0x00000169, 0x00000169, },
1648c2ecf20Sopenharmony_ci	{ 0x1c5a38, 0x00000009, 0x00000009, 0x000001a9, 0x000001a9, },
1658c2ecf20Sopenharmony_ci	{ 0x1c5a3c, 0x00000049, 0x00000049, 0x000001e9, 0x000001e9, },
1668c2ecf20Sopenharmony_ci	{ 0x1c5a40, 0x00000089, 0x00000089, 0x00000029, 0x00000029, },
1678c2ecf20Sopenharmony_ci	{ 0x1c5a44, 0x00000170, 0x00000170, 0x00000069, 0x00000069, },
1688c2ecf20Sopenharmony_ci	{ 0x1c5a48, 0x000001b0, 0x000001b0, 0x00000190, 0x00000190, },
1698c2ecf20Sopenharmony_ci	{ 0x1c5a4c, 0x000001f0, 0x000001f0, 0x000001d0, 0x000001d0, },
1708c2ecf20Sopenharmony_ci	{ 0x1c5a50, 0x00000030, 0x00000030, 0x00000010, 0x00000010, },
1718c2ecf20Sopenharmony_ci	{ 0x1c5a54, 0x00000070, 0x00000070, 0x00000050, 0x00000050, },
1728c2ecf20Sopenharmony_ci	{ 0x1c5a58, 0x00000191, 0x00000191, 0x00000090, 0x00000090, },
1738c2ecf20Sopenharmony_ci	{ 0x1c5a5c, 0x000001d1, 0x000001d1, 0x00000151, 0x00000151, },
1748c2ecf20Sopenharmony_ci	{ 0x1c5a60, 0x00000011, 0x00000011, 0x00000191, 0x00000191, },
1758c2ecf20Sopenharmony_ci	{ 0x1c5a64, 0x00000051, 0x00000051, 0x000001d1, 0x000001d1, },
1768c2ecf20Sopenharmony_ci	{ 0x1c5a68, 0x00000091, 0x00000091, 0x00000011, 0x00000011, },
1778c2ecf20Sopenharmony_ci	{ 0x1c5a6c, 0x000001b8, 0x000001b8, 0x00000051, 0x00000051, },
1788c2ecf20Sopenharmony_ci	{ 0x1c5a70, 0x000001f8, 0x000001f8, 0x00000198, 0x00000198, },
1798c2ecf20Sopenharmony_ci	{ 0x1c5a74, 0x00000038, 0x00000038, 0x000001d8, 0x000001d8, },
1808c2ecf20Sopenharmony_ci	{ 0x1c5a78, 0x00000078, 0x00000078, 0x00000018, 0x00000018, },
1818c2ecf20Sopenharmony_ci	{ 0x1c5a7c, 0x00000199, 0x00000199, 0x00000058, 0x00000058, },
1828c2ecf20Sopenharmony_ci	{ 0x1c5a80, 0x000001d9, 0x000001d9, 0x00000098, 0x00000098, },
1838c2ecf20Sopenharmony_ci	{ 0x1c5a84, 0x00000019, 0x00000019, 0x00000159, 0x00000159, },
1848c2ecf20Sopenharmony_ci	{ 0x1c5a88, 0x00000059, 0x00000059, 0x00000199, 0x00000199, },
1858c2ecf20Sopenharmony_ci	{ 0x1c5a8c, 0x00000099, 0x00000099, 0x000001d9, 0x000001d9, },
1868c2ecf20Sopenharmony_ci	{ 0x1c5a90, 0x000000d9, 0x000000d9, 0x00000019, 0x00000019, },
1878c2ecf20Sopenharmony_ci	{ 0x1c5a94, 0x000000f9, 0x000000f9, 0x00000059, 0x00000059, },
1888c2ecf20Sopenharmony_ci	{ 0x1c5a98, 0x000000f9, 0x000000f9, 0x00000099, 0x00000099, },
1898c2ecf20Sopenharmony_ci	{ 0x1c5a9c, 0x000000f9, 0x000000f9, 0x000000d9, 0x000000d9, },
1908c2ecf20Sopenharmony_ci	{ 0x1c5aa0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1918c2ecf20Sopenharmony_ci	{ 0x1c5aa4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1928c2ecf20Sopenharmony_ci	{ 0x1c5aa8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1938c2ecf20Sopenharmony_ci	{ 0x1c5aac, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1948c2ecf20Sopenharmony_ci	{ 0x1c5ab0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1958c2ecf20Sopenharmony_ci	{ 0x1c5ab4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1968c2ecf20Sopenharmony_ci	{ 0x1c5ab8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1978c2ecf20Sopenharmony_ci	{ 0x1c5abc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1988c2ecf20Sopenharmony_ci	{ 0x1c5ac0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
1998c2ecf20Sopenharmony_ci	{ 0x1c5ac4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2008c2ecf20Sopenharmony_ci	{ 0x1c5ac8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2018c2ecf20Sopenharmony_ci	{ 0x1c5acc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2028c2ecf20Sopenharmony_ci	{ 0x1c5ad0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2038c2ecf20Sopenharmony_ci	{ 0x1c5ad4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2048c2ecf20Sopenharmony_ci	{ 0x1c5ad8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2058c2ecf20Sopenharmony_ci	{ 0x1c5adc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2068c2ecf20Sopenharmony_ci	{ 0x1c5ae0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2078c2ecf20Sopenharmony_ci	{ 0x1c5ae4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2088c2ecf20Sopenharmony_ci	{ 0x1c5ae8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2098c2ecf20Sopenharmony_ci	{ 0x1c5aec, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2108c2ecf20Sopenharmony_ci	{ 0x1c5af0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2118c2ecf20Sopenharmony_ci	{ 0x1c5af4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2128c2ecf20Sopenharmony_ci	{ 0x1c5af8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2138c2ecf20Sopenharmony_ci	{ 0x1c5afc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
2148c2ecf20Sopenharmony_ci	{ 0x1c5b00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2158c2ecf20Sopenharmony_ci	{ 0x1c5b04, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
2168c2ecf20Sopenharmony_ci	{ 0x1c5b08, 0x00000002, 0x00000002, 0x00000002, 0x00000002, },
2178c2ecf20Sopenharmony_ci	{ 0x1c5b0c, 0x00000003, 0x00000003, 0x00000003, 0x00000003, },
2188c2ecf20Sopenharmony_ci	{ 0x1c5b10, 0x00000004, 0x00000004, 0x00000004, 0x00000004, },
2198c2ecf20Sopenharmony_ci	{ 0x1c5b14, 0x00000005, 0x00000005, 0x00000005, 0x00000005, },
2208c2ecf20Sopenharmony_ci	{ 0x1c5b18, 0x00000008, 0x00000008, 0x00000008, 0x00000008, },
2218c2ecf20Sopenharmony_ci	{ 0x1c5b1c, 0x00000009, 0x00000009, 0x00000009, 0x00000009, },
2228c2ecf20Sopenharmony_ci	{ 0x1c5b20, 0x0000000a, 0x0000000a, 0x0000000a, 0x0000000a, },
2238c2ecf20Sopenharmony_ci	{ 0x1c5b24, 0x0000000b, 0x0000000b, 0x0000000b, 0x0000000b, },
2248c2ecf20Sopenharmony_ci	{ 0x1c5b28, 0x0000000c, 0x0000000c, 0x0000000c, 0x0000000c, },
2258c2ecf20Sopenharmony_ci	{ 0x1c5b2c, 0x0000000d, 0x0000000d, 0x0000000d, 0x0000000d, },
2268c2ecf20Sopenharmony_ci	{ 0x1c5b30, 0x00000010, 0x00000010, 0x00000010, 0x00000010, },
2278c2ecf20Sopenharmony_ci	{ 0x1c5b34, 0x00000011, 0x00000011, 0x00000011, 0x00000011, },
2288c2ecf20Sopenharmony_ci	{ 0x1c5b38, 0x00000012, 0x00000012, 0x00000012, 0x00000012, },
2298c2ecf20Sopenharmony_ci	{ 0x1c5b3c, 0x00000013, 0x00000013, 0x00000013, 0x00000013, },
2308c2ecf20Sopenharmony_ci	{ 0x1c5b40, 0x00000014, 0x00000014, 0x00000014, 0x00000014, },
2318c2ecf20Sopenharmony_ci	{ 0x1c5b44, 0x00000015, 0x00000015, 0x00000015, 0x00000015, },
2328c2ecf20Sopenharmony_ci	{ 0x1c5b48, 0x00000018, 0x00000018, 0x00000018, 0x00000018, },
2338c2ecf20Sopenharmony_ci	{ 0x1c5b4c, 0x00000019, 0x00000019, 0x00000019, 0x00000019, },
2348c2ecf20Sopenharmony_ci	{ 0x1c5b50, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, },
2358c2ecf20Sopenharmony_ci	{ 0x1c5b54, 0x0000001b, 0x0000001b, 0x0000001b, 0x0000001b, },
2368c2ecf20Sopenharmony_ci	{ 0x1c5b58, 0x0000001c, 0x0000001c, 0x0000001c, 0x0000001c, },
2378c2ecf20Sopenharmony_ci	{ 0x1c5b5c, 0x0000001d, 0x0000001d, 0x0000001d, 0x0000001d, },
2388c2ecf20Sopenharmony_ci	{ 0x1c5b60, 0x00000020, 0x00000020, 0x00000020, 0x00000020, },
2398c2ecf20Sopenharmony_ci	{ 0x1c5b64, 0x00000021, 0x00000021, 0x00000021, 0x00000021, },
2408c2ecf20Sopenharmony_ci	{ 0x1c5b68, 0x00000022, 0x00000022, 0x00000022, 0x00000022, },
2418c2ecf20Sopenharmony_ci	{ 0x1c5b6c, 0x00000023, 0x00000023, 0x00000023, 0x00000023, },
2428c2ecf20Sopenharmony_ci	{ 0x1c5b70, 0x00000024, 0x00000024, 0x00000024, 0x00000024, },
2438c2ecf20Sopenharmony_ci	{ 0x1c5b74, 0x00000025, 0x00000025, 0x00000025, 0x00000025, },
2448c2ecf20Sopenharmony_ci	{ 0x1c5b78, 0x00000028, 0x00000028, 0x00000028, 0x00000028, },
2458c2ecf20Sopenharmony_ci	{ 0x1c5b7c, 0x00000029, 0x00000029, 0x00000029, 0x00000029, },
2468c2ecf20Sopenharmony_ci	{ 0x1c5b80, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, },
2478c2ecf20Sopenharmony_ci	{ 0x1c5b84, 0x0000002b, 0x0000002b, 0x0000002b, 0x0000002b, },
2488c2ecf20Sopenharmony_ci	{ 0x1c5b88, 0x0000002c, 0x0000002c, 0x0000002c, 0x0000002c, },
2498c2ecf20Sopenharmony_ci	{ 0x1c5b8c, 0x0000002d, 0x0000002d, 0x0000002d, 0x0000002d, },
2508c2ecf20Sopenharmony_ci	{ 0x1c5b90, 0x00000030, 0x00000030, 0x00000030, 0x00000030, },
2518c2ecf20Sopenharmony_ci	{ 0x1c5b94, 0x00000031, 0x00000031, 0x00000031, 0x00000031, },
2528c2ecf20Sopenharmony_ci	{ 0x1c5b98, 0x00000032, 0x00000032, 0x00000032, 0x00000032, },
2538c2ecf20Sopenharmony_ci	{ 0x1c5b9c, 0x00000033, 0x00000033, 0x00000033, 0x00000033, },
2548c2ecf20Sopenharmony_ci	{ 0x1c5ba0, 0x00000034, 0x00000034, 0x00000034, 0x00000034, },
2558c2ecf20Sopenharmony_ci	{ 0x1c5ba4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2568c2ecf20Sopenharmony_ci	{ 0x1c5ba8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2578c2ecf20Sopenharmony_ci	{ 0x1c5bac, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2588c2ecf20Sopenharmony_ci	{ 0x1c5bb0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2598c2ecf20Sopenharmony_ci	{ 0x1c5bb4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2608c2ecf20Sopenharmony_ci	{ 0x1c5bb8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2618c2ecf20Sopenharmony_ci	{ 0x1c5bbc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2628c2ecf20Sopenharmony_ci	{ 0x1c5bc0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2638c2ecf20Sopenharmony_ci	{ 0x1c5bc4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2648c2ecf20Sopenharmony_ci	{ 0x1c5bc8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2658c2ecf20Sopenharmony_ci	{ 0x1c5bcc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2668c2ecf20Sopenharmony_ci	{ 0x1c5bd0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2678c2ecf20Sopenharmony_ci	{ 0x1c5bd4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2688c2ecf20Sopenharmony_ci	{ 0x1c5bd8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2698c2ecf20Sopenharmony_ci	{ 0x1c5bdc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2708c2ecf20Sopenharmony_ci	{ 0x1c5be0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2718c2ecf20Sopenharmony_ci	{ 0x1c5be4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2728c2ecf20Sopenharmony_ci	{ 0x1c5be8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2738c2ecf20Sopenharmony_ci	{ 0x1c5bec, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2748c2ecf20Sopenharmony_ci	{ 0x1c5bf0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2758c2ecf20Sopenharmony_ci	{ 0x1c5bf4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
2768c2ecf20Sopenharmony_ci	{ 0x1c5bf8, 0x00000010, 0x00000010, 0x00000010, 0x00000010, },
2778c2ecf20Sopenharmony_ci	{ 0x1c5bfc, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, },
2788c2ecf20Sopenharmony_ci	{ 0x1c5c00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2798c2ecf20Sopenharmony_ci	{ 0x1c5c0c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2808c2ecf20Sopenharmony_ci	{ 0x1c5c10, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2818c2ecf20Sopenharmony_ci	{ 0x1c5c14, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2828c2ecf20Sopenharmony_ci	{ 0x1c5c18, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2838c2ecf20Sopenharmony_ci	{ 0x1c5c1c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2848c2ecf20Sopenharmony_ci	{ 0x1c5c20, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2858c2ecf20Sopenharmony_ci	{ 0x1c5c24, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2868c2ecf20Sopenharmony_ci	{ 0x1c5c28, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2878c2ecf20Sopenharmony_ci	{ 0x1c5c2c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2888c2ecf20Sopenharmony_ci	{ 0x1c5c30, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2898c2ecf20Sopenharmony_ci	{ 0x1c5c34, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2908c2ecf20Sopenharmony_ci	{ 0x1c5c38, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2918c2ecf20Sopenharmony_ci	{ 0x1c5c3c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2928c2ecf20Sopenharmony_ci	{ 0x1c5cf0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2938c2ecf20Sopenharmony_ci	{ 0x1c5cf4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2948c2ecf20Sopenharmony_ci	{ 0x1c5cf8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2958c2ecf20Sopenharmony_ci	{ 0x1c5cfc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
2968c2ecf20Sopenharmony_ci	{ 0x1c6200, 0x00000008, 0x00000008, 0x0000000e, 0x0000000e, },
2978c2ecf20Sopenharmony_ci	{ 0x1c6204, 0x00000440, 0x00000440, 0x00000440, 0x00000440, },
2988c2ecf20Sopenharmony_ci	{ 0x1c6208, 0xd6be4788, 0xd6be4788, 0xd03e4788, 0xd03e4788, },
2998c2ecf20Sopenharmony_ci	{ 0x1c620c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
3008c2ecf20Sopenharmony_ci	{ 0x1c6210, 0x40806333, 0x40806333, 0x40806333, 0x40806333, },
3018c2ecf20Sopenharmony_ci	{ 0x1c6214, 0x00106c10, 0x00106c10, 0x00106c10, 0x00106c10, },
3028c2ecf20Sopenharmony_ci	{ 0x1c6218, 0x009c4060, 0x009c4060, 0x009c4060, 0x009c4060, },
3038c2ecf20Sopenharmony_ci	{ 0x1c621c, 0x1883800a, 0x1883800a, 0x1883800a, 0x1883800a, },
3048c2ecf20Sopenharmony_ci	{ 0x1c6220, 0x018830c6, 0x018830c6, 0x018830c6, 0x018830c6, },
3058c2ecf20Sopenharmony_ci	{ 0x1c6224, 0x00000400, 0x00000400, 0x00000400, 0x00000400, },
3068c2ecf20Sopenharmony_ci	{ 0x1c6228, 0x000009b5, 0x000009b5, 0x000009b5, 0x000009b5, },
3078c2ecf20Sopenharmony_ci	{ 0x1c622c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3088c2ecf20Sopenharmony_ci	{ 0x1c6230, 0x00000108, 0x00000210, 0x00000210, 0x00000108, },
3098c2ecf20Sopenharmony_ci	{ 0x1c6234, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
3108c2ecf20Sopenharmony_ci	{ 0x1c6238, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
3118c2ecf20Sopenharmony_ci	{ 0x1c623c, 0x13c889af, 0x13c889af, 0x13c889af, 0x13c889af, },
3128c2ecf20Sopenharmony_ci	{ 0x1c6240, 0x38490a20, 0x38490a20, 0x38490a20, 0x38490a20, },
3138c2ecf20Sopenharmony_ci	{ 0x1c6244, 0x00007bb6, 0x00007bb6, 0x00007bb6, 0x00007bb6, },
3148c2ecf20Sopenharmony_ci	{ 0x1c6248, 0x0fff3ffc, 0x0fff3ffc, 0x0fff3ffc, 0x0fff3ffc, },
3158c2ecf20Sopenharmony_ci	{ 0x1c624c, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
3168c2ecf20Sopenharmony_ci	{ 0x1c6250, 0x0000a000, 0x0000a000, 0x0000a000, 0x0000a000, },
3178c2ecf20Sopenharmony_ci	{ 0x1c6254, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3188c2ecf20Sopenharmony_ci	{ 0x1c6258, 0x0cc75380, 0x0cc75380, 0x0cc75380, 0x0cc75380, },
3198c2ecf20Sopenharmony_ci	{ 0x1c625c, 0x0f0f0f01, 0x0f0f0f01, 0x0f0f0f01, 0x0f0f0f01, },
3208c2ecf20Sopenharmony_ci	{ 0x1c6260, 0xdfa91f01, 0xdfa91f01, 0xdfa91f01, 0xdfa91f01, },
3218c2ecf20Sopenharmony_ci	{ 0x1c6264, 0x00418a11, 0x00418a11, 0x00418a11, 0x00418a11, },
3228c2ecf20Sopenharmony_ci	{ 0x1c6268, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3238c2ecf20Sopenharmony_ci	{ 0x1c626c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
3248c2ecf20Sopenharmony_ci	{ 0x1c6274, 0x0a1a9caa, 0x0a1a9caa, 0x0a1a7caa, 0x0a1a7caa, },
3258c2ecf20Sopenharmony_ci	{ 0x1c6278, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
3268c2ecf20Sopenharmony_ci	{ 0x1c627c, 0x051701ce, 0x051701ce, 0x051701ce, 0x051701ce, },
3278c2ecf20Sopenharmony_ci	{ 0x1c6300, 0x18010000, 0x18010000, 0x18010000, 0x18010000, },
3288c2ecf20Sopenharmony_ci	{ 0x1c6304, 0x30032602, 0x30032602, 0x2e032402, 0x2e032402, },
3298c2ecf20Sopenharmony_ci	{ 0x1c6308, 0x48073e06, 0x48073e06, 0x4a0a3c06, 0x4a0a3c06, },
3308c2ecf20Sopenharmony_ci	{ 0x1c630c, 0x560b4c0a, 0x560b4c0a, 0x621a540b, 0x621a540b, },
3318c2ecf20Sopenharmony_ci	{ 0x1c6310, 0x641a600f, 0x641a600f, 0x764f6c1b, 0x764f6c1b, },
3328c2ecf20Sopenharmony_ci	{ 0x1c6314, 0x7a4f6e1b, 0x7a4f6e1b, 0x845b7a5a, 0x845b7a5a, },
3338c2ecf20Sopenharmony_ci	{ 0x1c6318, 0x8c5b7e5a, 0x8c5b7e5a, 0x950f8ccf, 0x950f8ccf, },
3348c2ecf20Sopenharmony_ci	{ 0x1c631c, 0x9d0f96cf, 0x9d0f96cf, 0xa5cf9b4f, 0xa5cf9b4f, },
3358c2ecf20Sopenharmony_ci	{ 0x1c6320, 0xb51fa69f, 0xb51fa69f, 0xbddfaf1f, 0xbddfaf1f, },
3368c2ecf20Sopenharmony_ci	{ 0x1c6324, 0xcb3fbd07, 0xcb3fbcbf, 0xd1ffc93f, 0xd1ffc93f, },
3378c2ecf20Sopenharmony_ci	{ 0x1c6328, 0x0000d7bf, 0x0000d7bf, 0x00000000, 0x00000000, },
3388c2ecf20Sopenharmony_ci	{ 0x1c632c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3398c2ecf20Sopenharmony_ci	{ 0x1c6330, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3408c2ecf20Sopenharmony_ci	{ 0x1c6334, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3418c2ecf20Sopenharmony_ci	{ 0x1c6338, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3428c2ecf20Sopenharmony_ci	{ 0x1c633c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3438c2ecf20Sopenharmony_ci	{ 0x1c6340, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3448c2ecf20Sopenharmony_ci	{ 0x1c6344, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3458c2ecf20Sopenharmony_ci	{ 0x1c6348, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
3468c2ecf20Sopenharmony_ci	{ 0x1c634c, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
3478c2ecf20Sopenharmony_ci	{ 0x1c6350, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
3488c2ecf20Sopenharmony_ci	{ 0x1c6354, 0x0003ffff, 0x0003ffff, 0x0003ffff, 0x0003ffff, },
3498c2ecf20Sopenharmony_ci	{ 0x1c6358, 0x79a8aa1f, 0x79a8aa1f, 0x79a8aa1f, 0x79a8aa1f, },
3508c2ecf20Sopenharmony_ci	{ 0x1c6388, 0x08000000, 0x08000000, 0x08000000, 0x08000000, },
3518c2ecf20Sopenharmony_ci	{ 0x1c638c, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
3528c2ecf20Sopenharmony_ci	{ 0x1c6390, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
3538c2ecf20Sopenharmony_ci	{ 0x1c6394, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
3548c2ecf20Sopenharmony_ci	{ 0x1c6398, 0x000001ce, 0x000001ce, 0x000001ce, 0x000001ce, },
3558c2ecf20Sopenharmony_ci	{ 0x1c639c, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
3568c2ecf20Sopenharmony_ci	{ 0x1c63a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3578c2ecf20Sopenharmony_ci	{ 0x1c63a4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3588c2ecf20Sopenharmony_ci	{ 0x1c63a8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3598c2ecf20Sopenharmony_ci	{ 0x1c63ac, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3608c2ecf20Sopenharmony_ci	{ 0x1c63b0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3618c2ecf20Sopenharmony_ci	{ 0x1c63b4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3628c2ecf20Sopenharmony_ci	{ 0x1c63b8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3638c2ecf20Sopenharmony_ci	{ 0x1c63bc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3648c2ecf20Sopenharmony_ci	{ 0x1c63c0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3658c2ecf20Sopenharmony_ci	{ 0x1c63c4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3668c2ecf20Sopenharmony_ci	{ 0x1c63c8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3678c2ecf20Sopenharmony_ci	{ 0x1c63cc, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
3688c2ecf20Sopenharmony_ci	{ 0x1c63d0, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
3698c2ecf20Sopenharmony_ci	{ 0x1c63d4, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
3708c2ecf20Sopenharmony_ci	{ 0x1c63d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
3718c2ecf20Sopenharmony_ci	{ 0x1c63dc, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
3728c2ecf20Sopenharmony_ci	{ 0x1c63e0, 0x000000c0, 0x000000c0, 0x000000c0, 0x000000c0, },
3738c2ecf20Sopenharmony_ci	{ 0x1c6848, 0x00180a65, 0x00180a65, 0x00180a68, 0x00180a68, },
3748c2ecf20Sopenharmony_ci	{ 0x1c6920, 0x0510001c, 0x0510001c, 0x0510001c, 0x0510001c, },
3758c2ecf20Sopenharmony_ci	{ 0x1c6960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
3768c2ecf20Sopenharmony_ci	{ 0x1c720c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
3778c2ecf20Sopenharmony_ci	{ 0x1c726c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
3788c2ecf20Sopenharmony_ci	{ 0x1c7848, 0x00180a65, 0x00180a65, 0x00180a68, 0x00180a68, },
3798c2ecf20Sopenharmony_ci	{ 0x1c7920, 0x0510001c, 0x0510001c, 0x0510001c, 0x0510001c, },
3808c2ecf20Sopenharmony_ci	{ 0x1c7960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
3818c2ecf20Sopenharmony_ci	{ 0x1c820c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
3828c2ecf20Sopenharmony_ci	{ 0x1c826c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
3838c2ecf20Sopenharmony_ci/*	{ 0x1c8864, 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00, }, */
3848c2ecf20Sopenharmony_ci	{ 0x1c8864, 0x0001c600, 0x0001c600, 0x0001c600, 0x0001c600, },
3858c2ecf20Sopenharmony_ci	{ 0x1c895c, 0x004b6a8e, 0x004b6a8e, 0x004b6a8e, 0x004b6a8e, },
3868c2ecf20Sopenharmony_ci	{ 0x1c8968, 0x000003ce, 0x000003ce, 0x000003ce, 0x000003ce, },
3878c2ecf20Sopenharmony_ci	{ 0x1c89bc, 0x00181400, 0x00181400, 0x00181400, 0x00181400, },
3888c2ecf20Sopenharmony_ci	{ 0x1c9270, 0x00820820, 0x00820820, 0x00820820, 0x00820820, },
3898c2ecf20Sopenharmony_ci	{ 0x1c935c, 0x066c420f, 0x066c420f, 0x066c420f, 0x066c420f, },
3908c2ecf20Sopenharmony_ci	{ 0x1c9360, 0x0f282207, 0x0f282207, 0x0f282207, 0x0f282207, },
3918c2ecf20Sopenharmony_ci	{ 0x1c9364, 0x17601685, 0x17601685, 0x17601685, 0x17601685, },
3928c2ecf20Sopenharmony_ci	{ 0x1c9368, 0x1f801104, 0x1f801104, 0x1f801104, 0x1f801104, },
3938c2ecf20Sopenharmony_ci	{ 0x1c936c, 0x37a00c03, 0x37a00c03, 0x37a00c03, 0x37a00c03, },
3948c2ecf20Sopenharmony_ci	{ 0x1c9370, 0x3fc40883, 0x3fc40883, 0x3fc40883, 0x3fc40883, },
3958c2ecf20Sopenharmony_ci	{ 0x1c9374, 0x57c00803, 0x57c00803, 0x57c00803, 0x57c00803, },
3968c2ecf20Sopenharmony_ci	{ 0x1c9378, 0x5fd80682, 0x5fd80682, 0x5fd80682, 0x5fd80682, },
3978c2ecf20Sopenharmony_ci	{ 0x1c937c, 0x7fe00482, 0x7fe00482, 0x7fe00482, 0x7fe00482, },
3988c2ecf20Sopenharmony_ci	{ 0x1c9380, 0x7f3c7bba, 0x7f3c7bba, 0x7f3c7bba, 0x7f3c7bba, },
3998c2ecf20Sopenharmony_ci	{ 0x1c9384, 0xf3307ff0, 0xf3307ff0, 0xf3307ff0, 0xf3307ff0, }
4008c2ecf20Sopenharmony_ci};
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci/*
4038c2ecf20Sopenharmony_ci * look up a certain register in ar5416_phy_init[] and return the init. value
4048c2ecf20Sopenharmony_ci * for the band and bandwidth given. Return 0 if register address not found.
4058c2ecf20Sopenharmony_ci */
4068c2ecf20Sopenharmony_cistatic u32 carl9170_def_val(u32 reg, bool is_2ghz, bool is_40mhz)
4078c2ecf20Sopenharmony_ci{
4088c2ecf20Sopenharmony_ci	unsigned int i;
4098c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(ar5416_phy_init); i++) {
4108c2ecf20Sopenharmony_ci		if (ar5416_phy_init[i].reg != reg)
4118c2ecf20Sopenharmony_ci			continue;
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci		if (is_2ghz) {
4148c2ecf20Sopenharmony_ci			if (is_40mhz)
4158c2ecf20Sopenharmony_ci				return ar5416_phy_init[i]._2ghz_40;
4168c2ecf20Sopenharmony_ci			else
4178c2ecf20Sopenharmony_ci				return ar5416_phy_init[i]._2ghz_20;
4188c2ecf20Sopenharmony_ci		} else {
4198c2ecf20Sopenharmony_ci			if (is_40mhz)
4208c2ecf20Sopenharmony_ci				return ar5416_phy_init[i]._5ghz_40;
4218c2ecf20Sopenharmony_ci			else
4228c2ecf20Sopenharmony_ci				return ar5416_phy_init[i]._5ghz_20;
4238c2ecf20Sopenharmony_ci		}
4248c2ecf20Sopenharmony_ci	}
4258c2ecf20Sopenharmony_ci	return 0;
4268c2ecf20Sopenharmony_ci}
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci/*
4298c2ecf20Sopenharmony_ci * initialize some phy regs from eeprom values in modal_header[]
4308c2ecf20Sopenharmony_ci * acc. to band and bandwidth
4318c2ecf20Sopenharmony_ci */
4328c2ecf20Sopenharmony_cistatic int carl9170_init_phy_from_eeprom(struct ar9170 *ar,
4338c2ecf20Sopenharmony_ci				bool is_2ghz, bool is_40mhz)
4348c2ecf20Sopenharmony_ci{
4358c2ecf20Sopenharmony_ci	static const u8 xpd2pd[16] = {
4368c2ecf20Sopenharmony_ci		0x2, 0x2, 0x2, 0x1, 0x2, 0x2, 0x6, 0x2,
4378c2ecf20Sopenharmony_ci		0x2, 0x3, 0x7, 0x2, 0xb, 0x2, 0x2, 0x2
4388c2ecf20Sopenharmony_ci	};
4398c2ecf20Sopenharmony_ci	/* pointer to the modal_header acc. to band */
4408c2ecf20Sopenharmony_ci	struct ar9170_eeprom_modal *m = &ar->eeprom.modal_header[is_2ghz];
4418c2ecf20Sopenharmony_ci	u32 val;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	carl9170_regwrite_begin(ar);
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	/* ant common control (index 0) */
4468c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_SWITCH_COM,
4478c2ecf20Sopenharmony_ci		le32_to_cpu(m->antCtrlCommon));
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	/* ant control chain 0 (index 1) */
4508c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_SWITCH_CHAIN_0,
4518c2ecf20Sopenharmony_ci		le32_to_cpu(m->antCtrlChain[0]));
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	/* ant control chain 2 (index 2) */
4548c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_SWITCH_CHAIN_2,
4558c2ecf20Sopenharmony_ci		le32_to_cpu(m->antCtrlChain[1]));
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	/* SwSettle (index 3) */
4588c2ecf20Sopenharmony_ci	if (!is_40mhz) {
4598c2ecf20Sopenharmony_ci		val = carl9170_def_val(AR9170_PHY_REG_SETTLING,
4608c2ecf20Sopenharmony_ci				     is_2ghz, is_40mhz);
4618c2ecf20Sopenharmony_ci		SET_VAL(AR9170_PHY_SETTLING_SWITCH, val, m->switchSettling);
4628c2ecf20Sopenharmony_ci		carl9170_regwrite(AR9170_PHY_REG_SETTLING, val);
4638c2ecf20Sopenharmony_ci	}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	/* adcDesired, pdaDesired (index 4) */
4668c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_DESIRED_SZ, is_2ghz, is_40mhz);
4678c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_DESIRED_SZ_PGA, val, m->pgaDesiredSize);
4688c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_DESIRED_SZ_ADC, val, m->adcDesiredSize);
4698c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_DESIRED_SZ, val);
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	/* TxEndToXpaOff, TxFrameToXpaOn (index 5) */
4728c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_RF_CTL4, is_2ghz, is_40mhz);
4738c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_RF_CTL4_TX_END_XPAB_OFF, val, m->txEndToXpaOff);
4748c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_RF_CTL4_TX_END_XPAA_OFF, val, m->txEndToXpaOff);
4758c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_RF_CTL4_FRAME_XPAB_ON, val, m->txFrameToXpaOn);
4768c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_RF_CTL4_FRAME_XPAA_ON, val, m->txFrameToXpaOn);
4778c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_RF_CTL4, val);
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci	/* TxEndToRxOn (index 6) */
4808c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_RF_CTL3, is_2ghz, is_40mhz);
4818c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_RF_CTL3_TX_END_TO_A2_RX_ON, val, m->txEndToRxOn);
4828c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_RF_CTL3, val);
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci	/* thresh62 (index 7) */
4858c2ecf20Sopenharmony_ci	val = carl9170_def_val(0x1c8864, is_2ghz, is_40mhz);
4868c2ecf20Sopenharmony_ci	val = (val & ~0x7f000) | (m->thresh62 << 12);
4878c2ecf20Sopenharmony_ci	carl9170_regwrite(0x1c8864, val);
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	/* tx/rx attenuation chain 0 (index 8) */
4908c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_RXGAIN, is_2ghz, is_40mhz);
4918c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_RXGAIN_TXRX_ATTEN, val, m->txRxAttenCh[0]);
4928c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_RXGAIN, val);
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	/* tx/rx attenuation chain 2 (index 9) */
4958c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_RXGAIN_CHAIN_2,
4968c2ecf20Sopenharmony_ci			       is_2ghz, is_40mhz);
4978c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_RXGAIN_TXRX_ATTEN, val, m->txRxAttenCh[1]);
4988c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_RXGAIN_CHAIN_2, val);
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci	/* tx/rx margin chain 0 (index 10) */
5018c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_GAIN_2GHZ, is_2ghz, is_40mhz);
5028c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_GAIN_2GHZ_RXTX_MARGIN, val, m->rxTxMarginCh[0]);
5038c2ecf20Sopenharmony_ci	/* bsw margin chain 0 for 5GHz only */
5048c2ecf20Sopenharmony_ci	if (!is_2ghz)
5058c2ecf20Sopenharmony_ci		SET_VAL(AR9170_PHY_GAIN_2GHZ_BSW_MARGIN, val, m->bswMargin[0]);
5068c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_GAIN_2GHZ, val);
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	/* tx/rx margin chain 2 (index 11) */
5098c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_GAIN_2GHZ_CHAIN_2,
5108c2ecf20Sopenharmony_ci			       is_2ghz, is_40mhz);
5118c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_GAIN_2GHZ_RXTX_MARGIN, val, m->rxTxMarginCh[1]);
5128c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_GAIN_2GHZ_CHAIN_2, val);
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	/* iqCall, iqCallq chain 0 (index 12) */
5158c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_TIMING_CTRL4(0),
5168c2ecf20Sopenharmony_ci			       is_2ghz, is_40mhz);
5178c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF, val, m->iqCalICh[0]);
5188c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF, val, m->iqCalQCh[0]);
5198c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_TIMING_CTRL4(0), val);
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	/* iqCall, iqCallq chain 2 (index 13) */
5228c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_TIMING_CTRL4(2),
5238c2ecf20Sopenharmony_ci			       is_2ghz, is_40mhz);
5248c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF, val, m->iqCalICh[1]);
5258c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF, val, m->iqCalQCh[1]);
5268c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_TIMING_CTRL4(2), val);
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	/* xpd gain mask (index 14) */
5298c2ecf20Sopenharmony_ci	val = carl9170_def_val(AR9170_PHY_REG_TPCRG1, is_2ghz, is_40mhz);
5308c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_TPCRG1_PD_GAIN_1, val,
5318c2ecf20Sopenharmony_ci		xpd2pd[m->xpdGain & 0xf] & 3);
5328c2ecf20Sopenharmony_ci	SET_VAL(AR9170_PHY_TPCRG1_PD_GAIN_2, val,
5338c2ecf20Sopenharmony_ci		xpd2pd[m->xpdGain & 0xf] >> 2);
5348c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_TPCRG1, val);
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_RX_CHAINMASK, ar->eeprom.rx_mask);
5378c2ecf20Sopenharmony_ci	carl9170_regwrite(AR9170_PHY_REG_CAL_CHAINMASK, ar->eeprom.rx_mask);
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci	carl9170_regwrite_finish();
5408c2ecf20Sopenharmony_ci	return carl9170_regwrite_result();
5418c2ecf20Sopenharmony_ci}
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_cistatic int carl9170_init_phy(struct ar9170 *ar, enum nl80211_band band)
5448c2ecf20Sopenharmony_ci{
5458c2ecf20Sopenharmony_ci	int i, err;
5468c2ecf20Sopenharmony_ci	u32 val;
5478c2ecf20Sopenharmony_ci	bool is_2ghz = band == NL80211_BAND_2GHZ;
5488c2ecf20Sopenharmony_ci	bool is_40mhz = conf_is_ht40(&ar->hw->conf);
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci	carl9170_regwrite_begin(ar);
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(ar5416_phy_init); i++) {
5538c2ecf20Sopenharmony_ci		if (is_40mhz) {
5548c2ecf20Sopenharmony_ci			if (is_2ghz)
5558c2ecf20Sopenharmony_ci				val = ar5416_phy_init[i]._2ghz_40;
5568c2ecf20Sopenharmony_ci			else
5578c2ecf20Sopenharmony_ci				val = ar5416_phy_init[i]._5ghz_40;
5588c2ecf20Sopenharmony_ci		} else {
5598c2ecf20Sopenharmony_ci			if (is_2ghz)
5608c2ecf20Sopenharmony_ci				val = ar5416_phy_init[i]._2ghz_20;
5618c2ecf20Sopenharmony_ci			else
5628c2ecf20Sopenharmony_ci				val = ar5416_phy_init[i]._5ghz_20;
5638c2ecf20Sopenharmony_ci		}
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci		carl9170_regwrite(ar5416_phy_init[i].reg, val);
5668c2ecf20Sopenharmony_ci	}
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci	carl9170_regwrite_finish();
5698c2ecf20Sopenharmony_ci	err = carl9170_regwrite_result();
5708c2ecf20Sopenharmony_ci	if (err)
5718c2ecf20Sopenharmony_ci		return err;
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci	err = carl9170_init_phy_from_eeprom(ar, is_2ghz, is_40mhz);
5748c2ecf20Sopenharmony_ci	if (err)
5758c2ecf20Sopenharmony_ci		return err;
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci	err = carl9170_init_power_cal(ar);
5788c2ecf20Sopenharmony_ci	if (err)
5798c2ecf20Sopenharmony_ci		return err;
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci	if (!ar->fw.hw_counters) {
5828c2ecf20Sopenharmony_ci		err = carl9170_write_reg(ar, AR9170_PWR_REG_PLL_ADDAC,
5838c2ecf20Sopenharmony_ci					 is_2ghz ? 0x5163 : 0x5143);
5848c2ecf20Sopenharmony_ci	}
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci	return err;
5878c2ecf20Sopenharmony_ci}
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_cistruct carl9170_rf_initvals {
5908c2ecf20Sopenharmony_ci	u32 reg, _5ghz, _2ghz;
5918c2ecf20Sopenharmony_ci};
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_cistatic struct carl9170_rf_initvals carl9170_rf_initval[] = {
5948c2ecf20Sopenharmony_ci	/* bank 0 */
5958c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x1e5795e5, 0x1e5795e5},
5968c2ecf20Sopenharmony_ci	{ 0x1c58e0, 0x02008020, 0x02008020},
5978c2ecf20Sopenharmony_ci	/* bank 1 */
5988c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x02108421, 0x02108421},
5998c2ecf20Sopenharmony_ci	{ 0x1c58ec, 0x00000008, 0x00000008},
6008c2ecf20Sopenharmony_ci	/* bank 2 */
6018c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x0e73ff17, 0x0e73ff17},
6028c2ecf20Sopenharmony_ci	{ 0x1c58e0, 0x00000420, 0x00000420},
6038c2ecf20Sopenharmony_ci	/* bank 3 */
6048c2ecf20Sopenharmony_ci	{ 0x1c58f0, 0x01400018, 0x01c00018},
6058c2ecf20Sopenharmony_ci	/* bank 4 */
6068c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x000001a1, 0x000001a1},
6078c2ecf20Sopenharmony_ci	{ 0x1c58e8, 0x00000001, 0x00000001},
6088c2ecf20Sopenharmony_ci	/* bank 5 */
6098c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000013, 0x00000013},
6108c2ecf20Sopenharmony_ci	{ 0x1c58e4, 0x00000002, 0x00000002},
6118c2ecf20Sopenharmony_ci	/* bank 6 */
6128c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000000, 0x00000000},
6138c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000000, 0x00000000},
6148c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000000, 0x00000000},
6158c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000000, 0x00000000},
6168c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000000, 0x00000000},
6178c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00004000, 0x00004000},
6188c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00006c00, 0x00006c00},
6198c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00002c00, 0x00002c00},
6208c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00004800, 0x00004800},
6218c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00004000, 0x00004000},
6228c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00006000, 0x00006000},
6238c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00001000, 0x00001000},
6248c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00004000, 0x00004000},
6258c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00007c00, 0x00007c00},
6268c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00007c00, 0x00007c00},
6278c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00007c00, 0x00007c00},
6288c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00007c00, 0x00007c00},
6298c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00007c00, 0x00007c00},
6308c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00087c00, 0x00087c00},
6318c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00007c00, 0x00007c00},
6328c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00005400, 0x00005400},
6338c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000c00, 0x00000c00},
6348c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00001800, 0x00001800},
6358c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00007c00, 0x00007c00},
6368c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00006c00, 0x00006c00},
6378c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00006c00, 0x00006c00},
6388c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00007c00, 0x00007c00},
6398c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00002c00, 0x00002c00},
6408c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00003c00, 0x00003c00},
6418c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00003800, 0x00003800},
6428c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00001c00, 0x00001c00},
6438c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000800, 0x00000800},
6448c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000408, 0x00000408},
6458c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00004c15, 0x00004c15},
6468c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00004188, 0x00004188},
6478c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x0000201e, 0x0000201e},
6488c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00010408, 0x00010408},
6498c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000801, 0x00000801},
6508c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000c08, 0x00000c08},
6518c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x0000181e, 0x0000181e},
6528c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00001016, 0x00001016},
6538c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00002800, 0x00002800},
6548c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00004010, 0x00004010},
6558c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x0000081c, 0x0000081c},
6568c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000115, 0x00000115},
6578c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000015, 0x00000015},
6588c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000066, 0x00000066},
6598c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x0000001c, 0x0000001c},
6608c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000000, 0x00000000},
6618c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000004, 0x00000004},
6628c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000015, 0x00000015},
6638c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x0000001f, 0x0000001f},
6648c2ecf20Sopenharmony_ci	{ 0x1c58e0, 0x00000000, 0x00000400},
6658c2ecf20Sopenharmony_ci	/* bank 7 */
6668c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x000000a0, 0x000000a0},
6678c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000000, 0x00000000},
6688c2ecf20Sopenharmony_ci	{ 0x1c58b0, 0x00000040, 0x00000040},
6698c2ecf20Sopenharmony_ci	{ 0x1c58f0, 0x0000001c, 0x0000001c},
6708c2ecf20Sopenharmony_ci};
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_cistatic int carl9170_init_rf_banks_0_7(struct ar9170 *ar, bool band5ghz)
6738c2ecf20Sopenharmony_ci{
6748c2ecf20Sopenharmony_ci	int err, i;
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	carl9170_regwrite_begin(ar);
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(carl9170_rf_initval); i++)
6798c2ecf20Sopenharmony_ci		carl9170_regwrite(carl9170_rf_initval[i].reg,
6808c2ecf20Sopenharmony_ci				  band5ghz ? carl9170_rf_initval[i]._5ghz
6818c2ecf20Sopenharmony_ci					   : carl9170_rf_initval[i]._2ghz);
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	carl9170_regwrite_finish();
6848c2ecf20Sopenharmony_ci	err = carl9170_regwrite_result();
6858c2ecf20Sopenharmony_ci	if (err)
6868c2ecf20Sopenharmony_ci		wiphy_err(ar->hw->wiphy, "rf init failed\n");
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci	return err;
6898c2ecf20Sopenharmony_ci}
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_cistruct carl9170_phy_freq_params {
6928c2ecf20Sopenharmony_ci	u8 coeff_exp;
6938c2ecf20Sopenharmony_ci	u16 coeff_man;
6948c2ecf20Sopenharmony_ci	u8 coeff_exp_shgi;
6958c2ecf20Sopenharmony_ci	u16 coeff_man_shgi;
6968c2ecf20Sopenharmony_ci};
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_cienum carl9170_bw {
6998c2ecf20Sopenharmony_ci	CARL9170_BW_20,
7008c2ecf20Sopenharmony_ci	CARL9170_BW_40_BELOW,
7018c2ecf20Sopenharmony_ci	CARL9170_BW_40_ABOVE,
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci	__CARL9170_NUM_BW,
7048c2ecf20Sopenharmony_ci};
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_cistruct carl9170_phy_freq_entry {
7078c2ecf20Sopenharmony_ci	u16 freq;
7088c2ecf20Sopenharmony_ci	struct carl9170_phy_freq_params params[__CARL9170_NUM_BW];
7098c2ecf20Sopenharmony_ci};
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci/* NB: must be in sync with channel tables in main! */
7128c2ecf20Sopenharmony_cistatic const struct carl9170_phy_freq_entry carl9170_phy_freq_params[] = {
7138c2ecf20Sopenharmony_ci/*
7148c2ecf20Sopenharmony_ci *	freq,
7158c2ecf20Sopenharmony_ci *		20MHz,
7168c2ecf20Sopenharmony_ci *		40MHz (below),
7178c2ecf20Sopenharmony_ci *		40Mhz (above),
7188c2ecf20Sopenharmony_ci */
7198c2ecf20Sopenharmony_ci	{ 2412, {
7208c2ecf20Sopenharmony_ci		{ 3, 21737, 3, 19563, },
7218c2ecf20Sopenharmony_ci		{ 3, 21827, 3, 19644, },
7228c2ecf20Sopenharmony_ci		{ 3, 21647, 3, 19482, },
7238c2ecf20Sopenharmony_ci	} },
7248c2ecf20Sopenharmony_ci	{ 2417, {
7258c2ecf20Sopenharmony_ci		{ 3, 21692, 3, 19523, },
7268c2ecf20Sopenharmony_ci		{ 3, 21782, 3, 19604, },
7278c2ecf20Sopenharmony_ci		{ 3, 21602, 3, 19442, },
7288c2ecf20Sopenharmony_ci	} },
7298c2ecf20Sopenharmony_ci	{ 2422, {
7308c2ecf20Sopenharmony_ci		{ 3, 21647, 3, 19482, },
7318c2ecf20Sopenharmony_ci		{ 3, 21737, 3, 19563, },
7328c2ecf20Sopenharmony_ci		{ 3, 21558, 3, 19402, },
7338c2ecf20Sopenharmony_ci	} },
7348c2ecf20Sopenharmony_ci	{ 2427, {
7358c2ecf20Sopenharmony_ci		{ 3, 21602, 3, 19442, },
7368c2ecf20Sopenharmony_ci		{ 3, 21692, 3, 19523, },
7378c2ecf20Sopenharmony_ci		{ 3, 21514, 3, 19362, },
7388c2ecf20Sopenharmony_ci	} },
7398c2ecf20Sopenharmony_ci	{ 2432, {
7408c2ecf20Sopenharmony_ci		{ 3, 21558, 3, 19402, },
7418c2ecf20Sopenharmony_ci		{ 3, 21647, 3, 19482, },
7428c2ecf20Sopenharmony_ci		{ 3, 21470, 3, 19323, },
7438c2ecf20Sopenharmony_ci	} },
7448c2ecf20Sopenharmony_ci	{ 2437, {
7458c2ecf20Sopenharmony_ci		{ 3, 21514, 3, 19362, },
7468c2ecf20Sopenharmony_ci		{ 3, 21602, 3, 19442, },
7478c2ecf20Sopenharmony_ci		{ 3, 21426, 3, 19283, },
7488c2ecf20Sopenharmony_ci	} },
7498c2ecf20Sopenharmony_ci	{ 2442, {
7508c2ecf20Sopenharmony_ci		{ 3, 21470, 3, 19323, },
7518c2ecf20Sopenharmony_ci		{ 3, 21558, 3, 19402, },
7528c2ecf20Sopenharmony_ci		{ 3, 21382, 3, 19244, },
7538c2ecf20Sopenharmony_ci	} },
7548c2ecf20Sopenharmony_ci	{ 2447, {
7558c2ecf20Sopenharmony_ci		{ 3, 21426, 3, 19283, },
7568c2ecf20Sopenharmony_ci		{ 3, 21514, 3, 19362, },
7578c2ecf20Sopenharmony_ci		{ 3, 21339, 3, 19205, },
7588c2ecf20Sopenharmony_ci	} },
7598c2ecf20Sopenharmony_ci	{ 2452, {
7608c2ecf20Sopenharmony_ci		{ 3, 21382, 3, 19244, },
7618c2ecf20Sopenharmony_ci		{ 3, 21470, 3, 19323, },
7628c2ecf20Sopenharmony_ci		{ 3, 21295, 3, 19166, },
7638c2ecf20Sopenharmony_ci	} },
7648c2ecf20Sopenharmony_ci	{ 2457, {
7658c2ecf20Sopenharmony_ci		{ 3, 21339, 3, 19205, },
7668c2ecf20Sopenharmony_ci		{ 3, 21426, 3, 19283, },
7678c2ecf20Sopenharmony_ci		{ 3, 21252, 3, 19127, },
7688c2ecf20Sopenharmony_ci	} },
7698c2ecf20Sopenharmony_ci	{ 2462, {
7708c2ecf20Sopenharmony_ci		{ 3, 21295, 3, 19166, },
7718c2ecf20Sopenharmony_ci		{ 3, 21382, 3, 19244, },
7728c2ecf20Sopenharmony_ci		{ 3, 21209, 3, 19088, },
7738c2ecf20Sopenharmony_ci	} },
7748c2ecf20Sopenharmony_ci	{ 2467, {
7758c2ecf20Sopenharmony_ci		{ 3, 21252, 3, 19127, },
7768c2ecf20Sopenharmony_ci		{ 3, 21339, 3, 19205, },
7778c2ecf20Sopenharmony_ci		{ 3, 21166, 3, 19050, },
7788c2ecf20Sopenharmony_ci	} },
7798c2ecf20Sopenharmony_ci	{ 2472, {
7808c2ecf20Sopenharmony_ci		{ 3, 21209, 3, 19088, },
7818c2ecf20Sopenharmony_ci		{ 3, 21295, 3, 19166, },
7828c2ecf20Sopenharmony_ci		{ 3, 21124, 3, 19011, },
7838c2ecf20Sopenharmony_ci	} },
7848c2ecf20Sopenharmony_ci	{ 2484, {
7858c2ecf20Sopenharmony_ci		{ 3, 21107, 3, 18996, },
7868c2ecf20Sopenharmony_ci		{ 3, 21192, 3, 19073, },
7878c2ecf20Sopenharmony_ci		{ 3, 21022, 3, 18920, },
7888c2ecf20Sopenharmony_ci	} },
7898c2ecf20Sopenharmony_ci	{ 4920, {
7908c2ecf20Sopenharmony_ci		{ 4, 21313, 4, 19181, },
7918c2ecf20Sopenharmony_ci		{ 4, 21356, 4, 19220, },
7928c2ecf20Sopenharmony_ci		{ 4, 21269, 4, 19142, },
7938c2ecf20Sopenharmony_ci	} },
7948c2ecf20Sopenharmony_ci	{ 4940, {
7958c2ecf20Sopenharmony_ci		{ 4, 21226, 4, 19104, },
7968c2ecf20Sopenharmony_ci		{ 4, 21269, 4, 19142, },
7978c2ecf20Sopenharmony_ci		{ 4, 21183, 4, 19065, },
7988c2ecf20Sopenharmony_ci	} },
7998c2ecf20Sopenharmony_ci	{ 4960, {
8008c2ecf20Sopenharmony_ci		{ 4, 21141, 4, 19027, },
8018c2ecf20Sopenharmony_ci		{ 4, 21183, 4, 19065, },
8028c2ecf20Sopenharmony_ci		{ 4, 21098, 4, 18988, },
8038c2ecf20Sopenharmony_ci	} },
8048c2ecf20Sopenharmony_ci	{ 4980, {
8058c2ecf20Sopenharmony_ci		{ 4, 21056, 4, 18950, },
8068c2ecf20Sopenharmony_ci		{ 4, 21098, 4, 18988, },
8078c2ecf20Sopenharmony_ci		{ 4, 21014, 4, 18912, },
8088c2ecf20Sopenharmony_ci	} },
8098c2ecf20Sopenharmony_ci	{ 5040, {
8108c2ecf20Sopenharmony_ci		{ 4, 20805, 4, 18725, },
8118c2ecf20Sopenharmony_ci		{ 4, 20846, 4, 18762, },
8128c2ecf20Sopenharmony_ci		{ 4, 20764, 4, 18687, },
8138c2ecf20Sopenharmony_ci	} },
8148c2ecf20Sopenharmony_ci	{ 5060, {
8158c2ecf20Sopenharmony_ci		{ 4, 20723, 4, 18651, },
8168c2ecf20Sopenharmony_ci		{ 4, 20764, 4, 18687, },
8178c2ecf20Sopenharmony_ci		{ 4, 20682, 4, 18614, },
8188c2ecf20Sopenharmony_ci	} },
8198c2ecf20Sopenharmony_ci	{ 5080, {
8208c2ecf20Sopenharmony_ci		{ 4, 20641, 4, 18577, },
8218c2ecf20Sopenharmony_ci		{ 4, 20682, 4, 18614, },
8228c2ecf20Sopenharmony_ci		{ 4, 20601, 4, 18541, },
8238c2ecf20Sopenharmony_ci	} },
8248c2ecf20Sopenharmony_ci	{ 5180, {
8258c2ecf20Sopenharmony_ci		{ 4, 20243, 4, 18219, },
8268c2ecf20Sopenharmony_ci		{ 4, 20282, 4, 18254, },
8278c2ecf20Sopenharmony_ci		{ 4, 20204, 4, 18183, },
8288c2ecf20Sopenharmony_ci	} },
8298c2ecf20Sopenharmony_ci	{ 5200, {
8308c2ecf20Sopenharmony_ci		{ 4, 20165, 4, 18148, },
8318c2ecf20Sopenharmony_ci		{ 4, 20204, 4, 18183, },
8328c2ecf20Sopenharmony_ci		{ 4, 20126, 4, 18114, },
8338c2ecf20Sopenharmony_ci	} },
8348c2ecf20Sopenharmony_ci	{ 5220, {
8358c2ecf20Sopenharmony_ci		{ 4, 20088, 4, 18079, },
8368c2ecf20Sopenharmony_ci		{ 4, 20126, 4, 18114, },
8378c2ecf20Sopenharmony_ci		{ 4, 20049, 4, 18044, },
8388c2ecf20Sopenharmony_ci	} },
8398c2ecf20Sopenharmony_ci	{ 5240, {
8408c2ecf20Sopenharmony_ci		{ 4, 20011, 4, 18010, },
8418c2ecf20Sopenharmony_ci		{ 4, 20049, 4, 18044, },
8428c2ecf20Sopenharmony_ci		{ 4, 19973, 4, 17976, },
8438c2ecf20Sopenharmony_ci	} },
8448c2ecf20Sopenharmony_ci	{ 5260, {
8458c2ecf20Sopenharmony_ci		{ 4, 19935, 4, 17941, },
8468c2ecf20Sopenharmony_ci		{ 4, 19973, 4, 17976, },
8478c2ecf20Sopenharmony_ci		{ 4, 19897, 4, 17907, },
8488c2ecf20Sopenharmony_ci	} },
8498c2ecf20Sopenharmony_ci	{ 5280, {
8508c2ecf20Sopenharmony_ci		{ 4, 19859, 4, 17873, },
8518c2ecf20Sopenharmony_ci		{ 4, 19897, 4, 17907, },
8528c2ecf20Sopenharmony_ci		{ 4, 19822, 4, 17840, },
8538c2ecf20Sopenharmony_ci	} },
8548c2ecf20Sopenharmony_ci	{ 5300, {
8558c2ecf20Sopenharmony_ci		{ 4, 19784, 4, 17806, },
8568c2ecf20Sopenharmony_ci		{ 4, 19822, 4, 17840, },
8578c2ecf20Sopenharmony_ci		{ 4, 19747, 4, 17772, },
8588c2ecf20Sopenharmony_ci	} },
8598c2ecf20Sopenharmony_ci	{ 5320, {
8608c2ecf20Sopenharmony_ci		{ 4, 19710, 4, 17739, },
8618c2ecf20Sopenharmony_ci		{ 4, 19747, 4, 17772, },
8628c2ecf20Sopenharmony_ci		{ 4, 19673, 4, 17706, },
8638c2ecf20Sopenharmony_ci	} },
8648c2ecf20Sopenharmony_ci	{ 5500, {
8658c2ecf20Sopenharmony_ci		{ 4, 19065, 4, 17159, },
8668c2ecf20Sopenharmony_ci		{ 4, 19100, 4, 17190, },
8678c2ecf20Sopenharmony_ci		{ 4, 19030, 4, 17127, },
8688c2ecf20Sopenharmony_ci	} },
8698c2ecf20Sopenharmony_ci	{ 5520, {
8708c2ecf20Sopenharmony_ci		{ 4, 18996, 4, 17096, },
8718c2ecf20Sopenharmony_ci		{ 4, 19030, 4, 17127, },
8728c2ecf20Sopenharmony_ci		{ 4, 18962, 4, 17065, },
8738c2ecf20Sopenharmony_ci	} },
8748c2ecf20Sopenharmony_ci	{ 5540, {
8758c2ecf20Sopenharmony_ci		{ 4, 18927, 4, 17035, },
8768c2ecf20Sopenharmony_ci		{ 4, 18962, 4, 17065, },
8778c2ecf20Sopenharmony_ci		{ 4, 18893, 4, 17004, },
8788c2ecf20Sopenharmony_ci	} },
8798c2ecf20Sopenharmony_ci	{ 5560, {
8808c2ecf20Sopenharmony_ci		{ 4, 18859, 4, 16973, },
8818c2ecf20Sopenharmony_ci		{ 4, 18893, 4, 17004, },
8828c2ecf20Sopenharmony_ci		{ 4, 18825, 4, 16943, },
8838c2ecf20Sopenharmony_ci	} },
8848c2ecf20Sopenharmony_ci	{ 5580, {
8858c2ecf20Sopenharmony_ci		{ 4, 18792, 4, 16913, },
8868c2ecf20Sopenharmony_ci		{ 4, 18825, 4, 16943, },
8878c2ecf20Sopenharmony_ci		{ 4, 18758, 4, 16882, },
8888c2ecf20Sopenharmony_ci	} },
8898c2ecf20Sopenharmony_ci	{ 5600, {
8908c2ecf20Sopenharmony_ci		{ 4, 18725, 4, 16852, },
8918c2ecf20Sopenharmony_ci		{ 4, 18758, 4, 16882, },
8928c2ecf20Sopenharmony_ci		{ 4, 18691, 4, 16822, },
8938c2ecf20Sopenharmony_ci	} },
8948c2ecf20Sopenharmony_ci	{ 5620, {
8958c2ecf20Sopenharmony_ci		{ 4, 18658, 4, 16792, },
8968c2ecf20Sopenharmony_ci		{ 4, 18691, 4, 16822, },
8978c2ecf20Sopenharmony_ci		{ 4, 18625, 4, 16762, },
8988c2ecf20Sopenharmony_ci	} },
8998c2ecf20Sopenharmony_ci	{ 5640, {
9008c2ecf20Sopenharmony_ci		{ 4, 18592, 4, 16733, },
9018c2ecf20Sopenharmony_ci		{ 4, 18625, 4, 16762, },
9028c2ecf20Sopenharmony_ci		{ 4, 18559, 4, 16703, },
9038c2ecf20Sopenharmony_ci	} },
9048c2ecf20Sopenharmony_ci	{ 5660, {
9058c2ecf20Sopenharmony_ci		{ 4, 18526, 4, 16673, },
9068c2ecf20Sopenharmony_ci		{ 4, 18559, 4, 16703, },
9078c2ecf20Sopenharmony_ci		{ 4, 18493, 4, 16644, },
9088c2ecf20Sopenharmony_ci	} },
9098c2ecf20Sopenharmony_ci	{ 5680, {
9108c2ecf20Sopenharmony_ci		{ 4, 18461, 4, 16615, },
9118c2ecf20Sopenharmony_ci		{ 4, 18493, 4, 16644, },
9128c2ecf20Sopenharmony_ci		{ 4, 18428, 4, 16586, },
9138c2ecf20Sopenharmony_ci	} },
9148c2ecf20Sopenharmony_ci	{ 5700, {
9158c2ecf20Sopenharmony_ci		{ 4, 18396, 4, 16556, },
9168c2ecf20Sopenharmony_ci		{ 4, 18428, 4, 16586, },
9178c2ecf20Sopenharmony_ci		{ 4, 18364, 4, 16527, },
9188c2ecf20Sopenharmony_ci	} },
9198c2ecf20Sopenharmony_ci	{ 5745, {
9208c2ecf20Sopenharmony_ci		{ 4, 18252, 4, 16427, },
9218c2ecf20Sopenharmony_ci		{ 4, 18284, 4, 16455, },
9228c2ecf20Sopenharmony_ci		{ 4, 18220, 4, 16398, },
9238c2ecf20Sopenharmony_ci	} },
9248c2ecf20Sopenharmony_ci	{ 5765, {
9258c2ecf20Sopenharmony_ci		{ 4, 18189, 5, 32740, },
9268c2ecf20Sopenharmony_ci		{ 4, 18220, 4, 16398, },
9278c2ecf20Sopenharmony_ci		{ 4, 18157, 5, 32683, },
9288c2ecf20Sopenharmony_ci	} },
9298c2ecf20Sopenharmony_ci	{ 5785, {
9308c2ecf20Sopenharmony_ci		{ 4, 18126, 5, 32626, },
9318c2ecf20Sopenharmony_ci		{ 4, 18157, 5, 32683, },
9328c2ecf20Sopenharmony_ci		{ 4, 18094, 5, 32570, },
9338c2ecf20Sopenharmony_ci	} },
9348c2ecf20Sopenharmony_ci	{ 5805, {
9358c2ecf20Sopenharmony_ci		{ 4, 18063, 5, 32514, },
9368c2ecf20Sopenharmony_ci		{ 4, 18094, 5, 32570, },
9378c2ecf20Sopenharmony_ci		{ 4, 18032, 5, 32458, },
9388c2ecf20Sopenharmony_ci	} },
9398c2ecf20Sopenharmony_ci	{ 5825, {
9408c2ecf20Sopenharmony_ci		{ 4, 18001, 5, 32402, },
9418c2ecf20Sopenharmony_ci		{ 4, 18032, 5, 32458, },
9428c2ecf20Sopenharmony_ci		{ 4, 17970, 5, 32347, },
9438c2ecf20Sopenharmony_ci	} },
9448c2ecf20Sopenharmony_ci	{ 5170, {
9458c2ecf20Sopenharmony_ci		{ 4, 20282, 4, 18254, },
9468c2ecf20Sopenharmony_ci		{ 4, 20321, 4, 18289, },
9478c2ecf20Sopenharmony_ci		{ 4, 20243, 4, 18219, },
9488c2ecf20Sopenharmony_ci	} },
9498c2ecf20Sopenharmony_ci	{ 5190, {
9508c2ecf20Sopenharmony_ci		{ 4, 20204, 4, 18183, },
9518c2ecf20Sopenharmony_ci		{ 4, 20243, 4, 18219, },
9528c2ecf20Sopenharmony_ci		{ 4, 20165, 4, 18148, },
9538c2ecf20Sopenharmony_ci	} },
9548c2ecf20Sopenharmony_ci	{ 5210, {
9558c2ecf20Sopenharmony_ci		{ 4, 20126, 4, 18114, },
9568c2ecf20Sopenharmony_ci		{ 4, 20165, 4, 18148, },
9578c2ecf20Sopenharmony_ci		{ 4, 20088, 4, 18079, },
9588c2ecf20Sopenharmony_ci	} },
9598c2ecf20Sopenharmony_ci	{ 5230, {
9608c2ecf20Sopenharmony_ci		{ 4, 20049, 4, 18044, },
9618c2ecf20Sopenharmony_ci		{ 4, 20088, 4, 18079, },
9628c2ecf20Sopenharmony_ci		{ 4, 20011, 4, 18010, },
9638c2ecf20Sopenharmony_ci	} },
9648c2ecf20Sopenharmony_ci};
9658c2ecf20Sopenharmony_ci
9668c2ecf20Sopenharmony_cistatic int carl9170_init_rf_bank4_pwr(struct ar9170 *ar, bool band5ghz,
9678c2ecf20Sopenharmony_ci				      u32 freq, enum carl9170_bw bw)
9688c2ecf20Sopenharmony_ci{
9698c2ecf20Sopenharmony_ci	int err;
9708c2ecf20Sopenharmony_ci	u32 d0, d1, td0, td1, fd0, fd1;
9718c2ecf20Sopenharmony_ci	u8 chansel;
9728c2ecf20Sopenharmony_ci	u8 refsel0 = 1, refsel1 = 0;
9738c2ecf20Sopenharmony_ci	u8 lf_synth = 0;
9748c2ecf20Sopenharmony_ci
9758c2ecf20Sopenharmony_ci	switch (bw) {
9768c2ecf20Sopenharmony_ci	case CARL9170_BW_40_ABOVE:
9778c2ecf20Sopenharmony_ci		freq += 10;
9788c2ecf20Sopenharmony_ci		break;
9798c2ecf20Sopenharmony_ci	case CARL9170_BW_40_BELOW:
9808c2ecf20Sopenharmony_ci		freq -= 10;
9818c2ecf20Sopenharmony_ci		break;
9828c2ecf20Sopenharmony_ci	case CARL9170_BW_20:
9838c2ecf20Sopenharmony_ci		break;
9848c2ecf20Sopenharmony_ci	default:
9858c2ecf20Sopenharmony_ci		BUG();
9868c2ecf20Sopenharmony_ci		return -ENOSYS;
9878c2ecf20Sopenharmony_ci	}
9888c2ecf20Sopenharmony_ci
9898c2ecf20Sopenharmony_ci	if (band5ghz) {
9908c2ecf20Sopenharmony_ci		if (freq % 10) {
9918c2ecf20Sopenharmony_ci			chansel = (freq - 4800) / 5;
9928c2ecf20Sopenharmony_ci		} else {
9938c2ecf20Sopenharmony_ci			chansel = ((freq - 4800) / 10) * 2;
9948c2ecf20Sopenharmony_ci			refsel0 = 0;
9958c2ecf20Sopenharmony_ci			refsel1 = 1;
9968c2ecf20Sopenharmony_ci		}
9978c2ecf20Sopenharmony_ci		chansel = bitrev8(chansel);
9988c2ecf20Sopenharmony_ci	} else {
9998c2ecf20Sopenharmony_ci		if (freq == 2484) {
10008c2ecf20Sopenharmony_ci			chansel = 10 + (freq - 2274) / 5;
10018c2ecf20Sopenharmony_ci			lf_synth = 1;
10028c2ecf20Sopenharmony_ci		} else
10038c2ecf20Sopenharmony_ci			chansel = 16 + (freq - 2272) / 5;
10048c2ecf20Sopenharmony_ci		chansel *= 4;
10058c2ecf20Sopenharmony_ci		chansel = bitrev8(chansel);
10068c2ecf20Sopenharmony_ci	}
10078c2ecf20Sopenharmony_ci
10088c2ecf20Sopenharmony_ci	d1 =	chansel;
10098c2ecf20Sopenharmony_ci	d0 =	0x21 |
10108c2ecf20Sopenharmony_ci		refsel0 << 3 |
10118c2ecf20Sopenharmony_ci		refsel1 << 2 |
10128c2ecf20Sopenharmony_ci		lf_synth << 1;
10138c2ecf20Sopenharmony_ci	td0 =	d0 & 0x1f;
10148c2ecf20Sopenharmony_ci	td1 =	d1 & 0x1f;
10158c2ecf20Sopenharmony_ci	fd0 =	td1 << 5 | td0;
10168c2ecf20Sopenharmony_ci
10178c2ecf20Sopenharmony_ci	td0 =	(d0 >> 5) & 0x7;
10188c2ecf20Sopenharmony_ci	td1 =	(d1 >> 5) & 0x7;
10198c2ecf20Sopenharmony_ci	fd1 =	td1 << 5 | td0;
10208c2ecf20Sopenharmony_ci
10218c2ecf20Sopenharmony_ci	carl9170_regwrite_begin(ar);
10228c2ecf20Sopenharmony_ci
10238c2ecf20Sopenharmony_ci	carl9170_regwrite(0x1c58b0, fd0);
10248c2ecf20Sopenharmony_ci	carl9170_regwrite(0x1c58e8, fd1);
10258c2ecf20Sopenharmony_ci
10268c2ecf20Sopenharmony_ci	carl9170_regwrite_finish();
10278c2ecf20Sopenharmony_ci	err = carl9170_regwrite_result();
10288c2ecf20Sopenharmony_ci	if (err)
10298c2ecf20Sopenharmony_ci		return err;
10308c2ecf20Sopenharmony_ci
10318c2ecf20Sopenharmony_ci	return 0;
10328c2ecf20Sopenharmony_ci}
10338c2ecf20Sopenharmony_ci
10348c2ecf20Sopenharmony_cistatic const struct carl9170_phy_freq_params *
10358c2ecf20Sopenharmony_cicarl9170_get_hw_dyn_params(struct ieee80211_channel *channel,
10368c2ecf20Sopenharmony_ci			   enum carl9170_bw bw)
10378c2ecf20Sopenharmony_ci{
10388c2ecf20Sopenharmony_ci	unsigned int chanidx = 0;
10398c2ecf20Sopenharmony_ci	u16 freq = 2412;
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_ci	if (channel) {
10428c2ecf20Sopenharmony_ci		chanidx = channel->hw_value;
10438c2ecf20Sopenharmony_ci		freq = channel->center_freq;
10448c2ecf20Sopenharmony_ci	}
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_ci	BUG_ON(chanidx >= ARRAY_SIZE(carl9170_phy_freq_params));
10478c2ecf20Sopenharmony_ci
10488c2ecf20Sopenharmony_ci	BUILD_BUG_ON(__CARL9170_NUM_BW != 3);
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci	WARN_ON(carl9170_phy_freq_params[chanidx].freq != freq);
10518c2ecf20Sopenharmony_ci
10528c2ecf20Sopenharmony_ci	return &carl9170_phy_freq_params[chanidx].params[bw];
10538c2ecf20Sopenharmony_ci}
10548c2ecf20Sopenharmony_ci
10558c2ecf20Sopenharmony_cistatic int carl9170_find_freq_idx(int nfreqs, u8 *freqs, u8 f)
10568c2ecf20Sopenharmony_ci{
10578c2ecf20Sopenharmony_ci	int idx = nfreqs - 2;
10588c2ecf20Sopenharmony_ci
10598c2ecf20Sopenharmony_ci	while (idx >= 0) {
10608c2ecf20Sopenharmony_ci		if (f >= freqs[idx])
10618c2ecf20Sopenharmony_ci			return idx;
10628c2ecf20Sopenharmony_ci		idx--;
10638c2ecf20Sopenharmony_ci	}
10648c2ecf20Sopenharmony_ci
10658c2ecf20Sopenharmony_ci	return 0;
10668c2ecf20Sopenharmony_ci}
10678c2ecf20Sopenharmony_ci
10688c2ecf20Sopenharmony_cistatic s32 carl9170_interpolate_s32(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
10698c2ecf20Sopenharmony_ci{
10708c2ecf20Sopenharmony_ci	/* nothing to interpolate, it's horizontal */
10718c2ecf20Sopenharmony_ci	if (y2 == y1)
10728c2ecf20Sopenharmony_ci		return y1;
10738c2ecf20Sopenharmony_ci
10748c2ecf20Sopenharmony_ci	/* check if we hit one of the edges */
10758c2ecf20Sopenharmony_ci	if (x == x1)
10768c2ecf20Sopenharmony_ci		return y1;
10778c2ecf20Sopenharmony_ci	if (x == x2)
10788c2ecf20Sopenharmony_ci		return y2;
10798c2ecf20Sopenharmony_ci
10808c2ecf20Sopenharmony_ci	/* x1 == x2 is bad, hopefully == x */
10818c2ecf20Sopenharmony_ci	if (x2 == x1)
10828c2ecf20Sopenharmony_ci		return y1;
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci	return y1 + (((y2 - y1) * (x - x1)) / (x2 - x1));
10858c2ecf20Sopenharmony_ci}
10868c2ecf20Sopenharmony_ci
10878c2ecf20Sopenharmony_cistatic u8 carl9170_interpolate_u8(u8 x, u8 x1, u8 y1, u8 x2, u8 y2)
10888c2ecf20Sopenharmony_ci{
10898c2ecf20Sopenharmony_ci#define SHIFT		8
10908c2ecf20Sopenharmony_ci	s32 y;
10918c2ecf20Sopenharmony_ci
10928c2ecf20Sopenharmony_ci	y = carl9170_interpolate_s32(x << SHIFT, x1 << SHIFT,
10938c2ecf20Sopenharmony_ci		y1 << SHIFT, x2 << SHIFT, y2 << SHIFT);
10948c2ecf20Sopenharmony_ci
10958c2ecf20Sopenharmony_ci	/*
10968c2ecf20Sopenharmony_ci	 * XXX: unwrap this expression
10978c2ecf20Sopenharmony_ci	 *	Isn't it just DIV_ROUND_UP(y, 1<<SHIFT)?
10988c2ecf20Sopenharmony_ci	 *	Can we rely on the compiler to optimise away the div?
10998c2ecf20Sopenharmony_ci	 */
11008c2ecf20Sopenharmony_ci	return (y >> SHIFT) + ((y & (1 << (SHIFT - 1))) >> (SHIFT - 1));
11018c2ecf20Sopenharmony_ci#undef SHIFT
11028c2ecf20Sopenharmony_ci}
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_cistatic u8 carl9170_interpolate_val(u8 x, u8 *x_array, u8 *y_array)
11058c2ecf20Sopenharmony_ci{
11068c2ecf20Sopenharmony_ci	int i;
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_ci	for (i = 0; i < 3; i++) {
11098c2ecf20Sopenharmony_ci		if (x <= x_array[i + 1])
11108c2ecf20Sopenharmony_ci			break;
11118c2ecf20Sopenharmony_ci	}
11128c2ecf20Sopenharmony_ci
11138c2ecf20Sopenharmony_ci	return carl9170_interpolate_u8(x, x_array[i], y_array[i],
11148c2ecf20Sopenharmony_ci		x_array[i + 1], y_array[i + 1]);
11158c2ecf20Sopenharmony_ci}
11168c2ecf20Sopenharmony_ci
11178c2ecf20Sopenharmony_cistatic int carl9170_set_freq_cal_data(struct ar9170 *ar,
11188c2ecf20Sopenharmony_ci	struct ieee80211_channel *channel)
11198c2ecf20Sopenharmony_ci{
11208c2ecf20Sopenharmony_ci	u8 *cal_freq_pier;
11218c2ecf20Sopenharmony_ci	u8 vpds[2][AR5416_PD_GAIN_ICEPTS];
11228c2ecf20Sopenharmony_ci	u8 pwrs[2][AR5416_PD_GAIN_ICEPTS];
11238c2ecf20Sopenharmony_ci	int chain, idx, i;
11248c2ecf20Sopenharmony_ci	u32 phy_data = 0;
11258c2ecf20Sopenharmony_ci	u8 f, tmp;
11268c2ecf20Sopenharmony_ci
11278c2ecf20Sopenharmony_ci	switch (channel->band) {
11288c2ecf20Sopenharmony_ci	case NL80211_BAND_2GHZ:
11298c2ecf20Sopenharmony_ci		f = channel->center_freq - 2300;
11308c2ecf20Sopenharmony_ci		cal_freq_pier = ar->eeprom.cal_freq_pier_2G;
11318c2ecf20Sopenharmony_ci		i = AR5416_NUM_2G_CAL_PIERS - 1;
11328c2ecf20Sopenharmony_ci		break;
11338c2ecf20Sopenharmony_ci
11348c2ecf20Sopenharmony_ci	case NL80211_BAND_5GHZ:
11358c2ecf20Sopenharmony_ci		f = (channel->center_freq - 4800) / 5;
11368c2ecf20Sopenharmony_ci		cal_freq_pier = ar->eeprom.cal_freq_pier_5G;
11378c2ecf20Sopenharmony_ci		i = AR5416_NUM_5G_CAL_PIERS - 1;
11388c2ecf20Sopenharmony_ci		break;
11398c2ecf20Sopenharmony_ci
11408c2ecf20Sopenharmony_ci	default:
11418c2ecf20Sopenharmony_ci		return -EINVAL;
11428c2ecf20Sopenharmony_ci	}
11438c2ecf20Sopenharmony_ci
11448c2ecf20Sopenharmony_ci	for (; i >= 0; i--) {
11458c2ecf20Sopenharmony_ci		if (cal_freq_pier[i] != 0xff)
11468c2ecf20Sopenharmony_ci			break;
11478c2ecf20Sopenharmony_ci	}
11488c2ecf20Sopenharmony_ci	if (i < 0)
11498c2ecf20Sopenharmony_ci		return -EINVAL;
11508c2ecf20Sopenharmony_ci
11518c2ecf20Sopenharmony_ci	idx = carl9170_find_freq_idx(i, cal_freq_pier, f);
11528c2ecf20Sopenharmony_ci
11538c2ecf20Sopenharmony_ci	carl9170_regwrite_begin(ar);
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci	for (chain = 0; chain < AR5416_MAX_CHAINS; chain++) {
11568c2ecf20Sopenharmony_ci		for (i = 0; i < AR5416_PD_GAIN_ICEPTS; i++) {
11578c2ecf20Sopenharmony_ci			struct ar9170_calibration_data_per_freq *cal_pier_data;
11588c2ecf20Sopenharmony_ci			int j;
11598c2ecf20Sopenharmony_ci
11608c2ecf20Sopenharmony_ci			switch (channel->band) {
11618c2ecf20Sopenharmony_ci			case NL80211_BAND_2GHZ:
11628c2ecf20Sopenharmony_ci				cal_pier_data = &ar->eeprom.
11638c2ecf20Sopenharmony_ci					cal_pier_data_2G[chain][idx];
11648c2ecf20Sopenharmony_ci				break;
11658c2ecf20Sopenharmony_ci
11668c2ecf20Sopenharmony_ci			case NL80211_BAND_5GHZ:
11678c2ecf20Sopenharmony_ci				cal_pier_data = &ar->eeprom.
11688c2ecf20Sopenharmony_ci					cal_pier_data_5G[chain][idx];
11698c2ecf20Sopenharmony_ci				break;
11708c2ecf20Sopenharmony_ci
11718c2ecf20Sopenharmony_ci			default:
11728c2ecf20Sopenharmony_ci				return -EINVAL;
11738c2ecf20Sopenharmony_ci			}
11748c2ecf20Sopenharmony_ci
11758c2ecf20Sopenharmony_ci			for (j = 0; j < 2; j++) {
11768c2ecf20Sopenharmony_ci				vpds[j][i] = carl9170_interpolate_u8(f,
11778c2ecf20Sopenharmony_ci					cal_freq_pier[idx],
11788c2ecf20Sopenharmony_ci					cal_pier_data->vpd_pdg[j][i],
11798c2ecf20Sopenharmony_ci					cal_freq_pier[idx + 1],
11808c2ecf20Sopenharmony_ci					cal_pier_data[1].vpd_pdg[j][i]);
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_ci				pwrs[j][i] = carl9170_interpolate_u8(f,
11838c2ecf20Sopenharmony_ci					cal_freq_pier[idx],
11848c2ecf20Sopenharmony_ci					cal_pier_data->pwr_pdg[j][i],
11858c2ecf20Sopenharmony_ci					cal_freq_pier[idx + 1],
11868c2ecf20Sopenharmony_ci					cal_pier_data[1].pwr_pdg[j][i]) / 2;
11878c2ecf20Sopenharmony_ci			}
11888c2ecf20Sopenharmony_ci		}
11898c2ecf20Sopenharmony_ci
11908c2ecf20Sopenharmony_ci		for (i = 0; i < 76; i++) {
11918c2ecf20Sopenharmony_ci			if (i < 25) {
11928c2ecf20Sopenharmony_ci				tmp = carl9170_interpolate_val(i, &pwrs[0][0],
11938c2ecf20Sopenharmony_ci							       &vpds[0][0]);
11948c2ecf20Sopenharmony_ci			} else {
11958c2ecf20Sopenharmony_ci				tmp = carl9170_interpolate_val(i - 12,
11968c2ecf20Sopenharmony_ci							       &pwrs[1][0],
11978c2ecf20Sopenharmony_ci							       &vpds[1][0]);
11988c2ecf20Sopenharmony_ci			}
11998c2ecf20Sopenharmony_ci
12008c2ecf20Sopenharmony_ci			phy_data |= tmp << ((i & 3) << 3);
12018c2ecf20Sopenharmony_ci			if ((i & 3) == 3) {
12028c2ecf20Sopenharmony_ci				carl9170_regwrite(0x1c6280 + chain * 0x1000 +
12038c2ecf20Sopenharmony_ci						  (i & ~3), phy_data);
12048c2ecf20Sopenharmony_ci				phy_data = 0;
12058c2ecf20Sopenharmony_ci			}
12068c2ecf20Sopenharmony_ci		}
12078c2ecf20Sopenharmony_ci
12088c2ecf20Sopenharmony_ci		for (i = 19; i < 32; i++)
12098c2ecf20Sopenharmony_ci			carl9170_regwrite(0x1c6280 + chain * 0x1000 + (i << 2),
12108c2ecf20Sopenharmony_ci					  0x0);
12118c2ecf20Sopenharmony_ci	}
12128c2ecf20Sopenharmony_ci
12138c2ecf20Sopenharmony_ci	carl9170_regwrite_finish();
12148c2ecf20Sopenharmony_ci	return carl9170_regwrite_result();
12158c2ecf20Sopenharmony_ci}
12168c2ecf20Sopenharmony_ci
12178c2ecf20Sopenharmony_cistatic u8 carl9170_get_max_edge_power(struct ar9170 *ar,
12188c2ecf20Sopenharmony_ci	u32 freq, struct ar9170_calctl_edges edges[])
12198c2ecf20Sopenharmony_ci{
12208c2ecf20Sopenharmony_ci	int i;
12218c2ecf20Sopenharmony_ci	u8 rc = AR5416_MAX_RATE_POWER;
12228c2ecf20Sopenharmony_ci	u8 f;
12238c2ecf20Sopenharmony_ci	if (freq < 3000)
12248c2ecf20Sopenharmony_ci		f = freq - 2300;
12258c2ecf20Sopenharmony_ci	else
12268c2ecf20Sopenharmony_ci		f = (freq - 4800) / 5;
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci	for (i = 0; i < AR5416_NUM_BAND_EDGES; i++) {
12298c2ecf20Sopenharmony_ci		if (edges[i].channel == 0xff)
12308c2ecf20Sopenharmony_ci			break;
12318c2ecf20Sopenharmony_ci		if (f == edges[i].channel) {
12328c2ecf20Sopenharmony_ci			/* exact freq match */
12338c2ecf20Sopenharmony_ci			rc = edges[i].power_flags & ~AR9170_CALCTL_EDGE_FLAGS;
12348c2ecf20Sopenharmony_ci			break;
12358c2ecf20Sopenharmony_ci		}
12368c2ecf20Sopenharmony_ci		if (i > 0 && f < edges[i].channel) {
12378c2ecf20Sopenharmony_ci			if (f > edges[i - 1].channel &&
12388c2ecf20Sopenharmony_ci			    edges[i - 1].power_flags &
12398c2ecf20Sopenharmony_ci			    AR9170_CALCTL_EDGE_FLAGS) {
12408c2ecf20Sopenharmony_ci				/* lower channel has the inband flag set */
12418c2ecf20Sopenharmony_ci				rc = edges[i - 1].power_flags &
12428c2ecf20Sopenharmony_ci					~AR9170_CALCTL_EDGE_FLAGS;
12438c2ecf20Sopenharmony_ci			}
12448c2ecf20Sopenharmony_ci			break;
12458c2ecf20Sopenharmony_ci		}
12468c2ecf20Sopenharmony_ci	}
12478c2ecf20Sopenharmony_ci
12488c2ecf20Sopenharmony_ci	if (i == AR5416_NUM_BAND_EDGES) {
12498c2ecf20Sopenharmony_ci		if (f > edges[i - 1].channel &&
12508c2ecf20Sopenharmony_ci		    edges[i - 1].power_flags & AR9170_CALCTL_EDGE_FLAGS) {
12518c2ecf20Sopenharmony_ci			/* lower channel has the inband flag set */
12528c2ecf20Sopenharmony_ci			rc = edges[i - 1].power_flags &
12538c2ecf20Sopenharmony_ci				~AR9170_CALCTL_EDGE_FLAGS;
12548c2ecf20Sopenharmony_ci		}
12558c2ecf20Sopenharmony_ci	}
12568c2ecf20Sopenharmony_ci	return rc;
12578c2ecf20Sopenharmony_ci}
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_cistatic u8 carl9170_get_heavy_clip(struct ar9170 *ar, u32 freq,
12608c2ecf20Sopenharmony_ci	enum carl9170_bw bw, struct ar9170_calctl_edges edges[])
12618c2ecf20Sopenharmony_ci{
12628c2ecf20Sopenharmony_ci	u8 f;
12638c2ecf20Sopenharmony_ci	int i;
12648c2ecf20Sopenharmony_ci	u8 rc = 0;
12658c2ecf20Sopenharmony_ci
12668c2ecf20Sopenharmony_ci	if (freq < 3000)
12678c2ecf20Sopenharmony_ci		f = freq - 2300;
12688c2ecf20Sopenharmony_ci	else
12698c2ecf20Sopenharmony_ci		f = (freq - 4800) / 5;
12708c2ecf20Sopenharmony_ci
12718c2ecf20Sopenharmony_ci	if (bw == CARL9170_BW_40_BELOW || bw == CARL9170_BW_40_ABOVE)
12728c2ecf20Sopenharmony_ci		rc |= 0xf0;
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_ci	for (i = 0; i < AR5416_NUM_BAND_EDGES; i++) {
12758c2ecf20Sopenharmony_ci		if (edges[i].channel == 0xff)
12768c2ecf20Sopenharmony_ci			break;
12778c2ecf20Sopenharmony_ci		if (f == edges[i].channel) {
12788c2ecf20Sopenharmony_ci			if (!(edges[i].power_flags & AR9170_CALCTL_EDGE_FLAGS))
12798c2ecf20Sopenharmony_ci				rc |= 0x0f;
12808c2ecf20Sopenharmony_ci			break;
12818c2ecf20Sopenharmony_ci		}
12828c2ecf20Sopenharmony_ci	}
12838c2ecf20Sopenharmony_ci
12848c2ecf20Sopenharmony_ci	return rc;
12858c2ecf20Sopenharmony_ci}
12868c2ecf20Sopenharmony_ci
12878c2ecf20Sopenharmony_ci/*
12888c2ecf20Sopenharmony_ci * calculate the conformance test limits and the heavy clip parameter
12898c2ecf20Sopenharmony_ci * and apply them to ar->power* (derived from otus hal/hpmain.c, line 3706)
12908c2ecf20Sopenharmony_ci */
12918c2ecf20Sopenharmony_cistatic void carl9170_calc_ctl(struct ar9170 *ar, u32 freq, enum carl9170_bw bw)
12928c2ecf20Sopenharmony_ci{
12938c2ecf20Sopenharmony_ci	u8 ctl_grp; /* CTL group */
12948c2ecf20Sopenharmony_ci	u8 ctl_idx; /* CTL index */
12958c2ecf20Sopenharmony_ci	int i, j;
12968c2ecf20Sopenharmony_ci	struct ctl_modes {
12978c2ecf20Sopenharmony_ci		u8 ctl_mode;
12988c2ecf20Sopenharmony_ci		u8 max_power;
12998c2ecf20Sopenharmony_ci		u8 *pwr_cal_data;
13008c2ecf20Sopenharmony_ci		int pwr_cal_len;
13018c2ecf20Sopenharmony_ci	} *modes;
13028c2ecf20Sopenharmony_ci
13038c2ecf20Sopenharmony_ci	/*
13048c2ecf20Sopenharmony_ci	 * order is relevant in the mode_list_*: we fall back to the
13058c2ecf20Sopenharmony_ci	 * lower indices if any mode is missed in the EEPROM.
13068c2ecf20Sopenharmony_ci	 */
13078c2ecf20Sopenharmony_ci	struct ctl_modes mode_list_2ghz[] = {
13088c2ecf20Sopenharmony_ci		{ CTL_11B, 0, ar->power_2G_cck, 4 },
13098c2ecf20Sopenharmony_ci		{ CTL_11G, 0, ar->power_2G_ofdm, 4 },
13108c2ecf20Sopenharmony_ci		{ CTL_2GHT20, 0, ar->power_2G_ht20, 8 },
13118c2ecf20Sopenharmony_ci		{ CTL_2GHT40, 0, ar->power_2G_ht40, 8 },
13128c2ecf20Sopenharmony_ci	};
13138c2ecf20Sopenharmony_ci	struct ctl_modes mode_list_5ghz[] = {
13148c2ecf20Sopenharmony_ci		{ CTL_11A, 0, ar->power_5G_leg, 4 },
13158c2ecf20Sopenharmony_ci		{ CTL_5GHT20, 0, ar->power_5G_ht20, 8 },
13168c2ecf20Sopenharmony_ci		{ CTL_5GHT40, 0, ar->power_5G_ht40, 8 },
13178c2ecf20Sopenharmony_ci	};
13188c2ecf20Sopenharmony_ci	int nr_modes;
13198c2ecf20Sopenharmony_ci
13208c2ecf20Sopenharmony_ci#define EDGES(c, n) (ar->eeprom.ctl_data[c].control_edges[n])
13218c2ecf20Sopenharmony_ci
13228c2ecf20Sopenharmony_ci	ar->heavy_clip = 0;
13238c2ecf20Sopenharmony_ci
13248c2ecf20Sopenharmony_ci	/*
13258c2ecf20Sopenharmony_ci	 * TODO: investigate the differences between OTUS'
13268c2ecf20Sopenharmony_ci	 * hpreg.c::zfHpGetRegulatoryDomain() and
13278c2ecf20Sopenharmony_ci	 * ath/regd.c::ath_regd_get_band_ctl() -
13288c2ecf20Sopenharmony_ci	 * e.g. for FCC3_WORLD the OTUS procedure
13298c2ecf20Sopenharmony_ci	 * always returns CTL_FCC, while the one in ath/ delivers
13308c2ecf20Sopenharmony_ci	 * CTL_ETSI for 2GHz and CTL_FCC for 5GHz.
13318c2ecf20Sopenharmony_ci	 */
13328c2ecf20Sopenharmony_ci	ctl_grp = ath_regd_get_band_ctl(&ar->common.regulatory,
13338c2ecf20Sopenharmony_ci					ar->hw->conf.chandef.chan->band);
13348c2ecf20Sopenharmony_ci
13358c2ecf20Sopenharmony_ci	/* ctl group not found - either invalid band (NO_CTL) or ww roaming */
13368c2ecf20Sopenharmony_ci	if (ctl_grp == NO_CTL || ctl_grp == SD_NO_CTL)
13378c2ecf20Sopenharmony_ci		ctl_grp = CTL_FCC;
13388c2ecf20Sopenharmony_ci
13398c2ecf20Sopenharmony_ci	if (ctl_grp != CTL_FCC)
13408c2ecf20Sopenharmony_ci		/* skip CTL and heavy clip for CTL_MKK and CTL_ETSI */
13418c2ecf20Sopenharmony_ci		return;
13428c2ecf20Sopenharmony_ci
13438c2ecf20Sopenharmony_ci	if (ar->hw->conf.chandef.chan->band == NL80211_BAND_2GHZ) {
13448c2ecf20Sopenharmony_ci		modes = mode_list_2ghz;
13458c2ecf20Sopenharmony_ci		nr_modes = ARRAY_SIZE(mode_list_2ghz);
13468c2ecf20Sopenharmony_ci	} else {
13478c2ecf20Sopenharmony_ci		modes = mode_list_5ghz;
13488c2ecf20Sopenharmony_ci		nr_modes = ARRAY_SIZE(mode_list_5ghz);
13498c2ecf20Sopenharmony_ci	}
13508c2ecf20Sopenharmony_ci
13518c2ecf20Sopenharmony_ci	for (i = 0; i < nr_modes; i++) {
13528c2ecf20Sopenharmony_ci		u8 c = ctl_grp | modes[i].ctl_mode;
13538c2ecf20Sopenharmony_ci		for (ctl_idx = 0; ctl_idx < AR5416_NUM_CTLS; ctl_idx++)
13548c2ecf20Sopenharmony_ci			if (c == ar->eeprom.ctl_index[ctl_idx])
13558c2ecf20Sopenharmony_ci				break;
13568c2ecf20Sopenharmony_ci		if (ctl_idx < AR5416_NUM_CTLS) {
13578c2ecf20Sopenharmony_ci			int f_off = 0;
13588c2ecf20Sopenharmony_ci
13598c2ecf20Sopenharmony_ci			/*
13608c2ecf20Sopenharmony_ci			 * determine heavy clip parameter
13618c2ecf20Sopenharmony_ci			 * from the 11G edges array
13628c2ecf20Sopenharmony_ci			 */
13638c2ecf20Sopenharmony_ci			if (modes[i].ctl_mode == CTL_11G) {
13648c2ecf20Sopenharmony_ci				ar->heavy_clip =
13658c2ecf20Sopenharmony_ci					carl9170_get_heavy_clip(ar,
13668c2ecf20Sopenharmony_ci						freq, bw, EDGES(ctl_idx, 1));
13678c2ecf20Sopenharmony_ci			}
13688c2ecf20Sopenharmony_ci
13698c2ecf20Sopenharmony_ci			/* adjust freq for 40MHz */
13708c2ecf20Sopenharmony_ci			if (modes[i].ctl_mode == CTL_2GHT40 ||
13718c2ecf20Sopenharmony_ci			    modes[i].ctl_mode == CTL_5GHT40) {
13728c2ecf20Sopenharmony_ci				if (bw == CARL9170_BW_40_BELOW)
13738c2ecf20Sopenharmony_ci					f_off = -10;
13748c2ecf20Sopenharmony_ci				else
13758c2ecf20Sopenharmony_ci					f_off = 10;
13768c2ecf20Sopenharmony_ci			}
13778c2ecf20Sopenharmony_ci
13788c2ecf20Sopenharmony_ci			modes[i].max_power =
13798c2ecf20Sopenharmony_ci				carl9170_get_max_edge_power(ar,
13808c2ecf20Sopenharmony_ci					freq + f_off, EDGES(ctl_idx, 1));
13818c2ecf20Sopenharmony_ci
13828c2ecf20Sopenharmony_ci			/*
13838c2ecf20Sopenharmony_ci			 * TODO: check if the regulatory max. power is
13848c2ecf20Sopenharmony_ci			 * controlled by cfg80211 for DFS.
13858c2ecf20Sopenharmony_ci			 * (hpmain applies it to max_power itself for DFS freq)
13868c2ecf20Sopenharmony_ci			 */
13878c2ecf20Sopenharmony_ci
13888c2ecf20Sopenharmony_ci		} else {
13898c2ecf20Sopenharmony_ci			/*
13908c2ecf20Sopenharmony_ci			 * Workaround in otus driver, hpmain.c, line 3906:
13918c2ecf20Sopenharmony_ci			 * if no data for 5GHT20 are found, take the
13928c2ecf20Sopenharmony_ci			 * legacy 5G value. We extend this here to fallback
13938c2ecf20Sopenharmony_ci			 * from any other HT* or 11G, too.
13948c2ecf20Sopenharmony_ci			 */
13958c2ecf20Sopenharmony_ci			int k = i;
13968c2ecf20Sopenharmony_ci
13978c2ecf20Sopenharmony_ci			modes[i].max_power = AR5416_MAX_RATE_POWER;
13988c2ecf20Sopenharmony_ci			while (k-- > 0) {
13998c2ecf20Sopenharmony_ci				if (modes[k].max_power !=
14008c2ecf20Sopenharmony_ci				    AR5416_MAX_RATE_POWER) {
14018c2ecf20Sopenharmony_ci					modes[i].max_power = modes[k].max_power;
14028c2ecf20Sopenharmony_ci					break;
14038c2ecf20Sopenharmony_ci				}
14048c2ecf20Sopenharmony_ci			}
14058c2ecf20Sopenharmony_ci		}
14068c2ecf20Sopenharmony_ci
14078c2ecf20Sopenharmony_ci		/* apply max power to pwr_cal_data (ar->power_*) */
14088c2ecf20Sopenharmony_ci		for (j = 0; j < modes[i].pwr_cal_len; j++) {
14098c2ecf20Sopenharmony_ci			modes[i].pwr_cal_data[j] = min(modes[i].pwr_cal_data[j],
14108c2ecf20Sopenharmony_ci						       modes[i].max_power);
14118c2ecf20Sopenharmony_ci		}
14128c2ecf20Sopenharmony_ci	}
14138c2ecf20Sopenharmony_ci
14148c2ecf20Sopenharmony_ci	if (ar->heavy_clip & 0xf0) {
14158c2ecf20Sopenharmony_ci		ar->power_2G_ht40[0]--;
14168c2ecf20Sopenharmony_ci		ar->power_2G_ht40[1]--;
14178c2ecf20Sopenharmony_ci		ar->power_2G_ht40[2]--;
14188c2ecf20Sopenharmony_ci	}
14198c2ecf20Sopenharmony_ci	if (ar->heavy_clip & 0xf) {
14208c2ecf20Sopenharmony_ci		ar->power_2G_ht20[0]++;
14218c2ecf20Sopenharmony_ci		ar->power_2G_ht20[1]++;
14228c2ecf20Sopenharmony_ci		ar->power_2G_ht20[2]++;
14238c2ecf20Sopenharmony_ci	}
14248c2ecf20Sopenharmony_ci
14258c2ecf20Sopenharmony_ci#undef EDGES
14268c2ecf20Sopenharmony_ci}
14278c2ecf20Sopenharmony_ci
14288c2ecf20Sopenharmony_cistatic void carl9170_set_power_cal(struct ar9170 *ar, u32 freq,
14298c2ecf20Sopenharmony_ci				   enum carl9170_bw bw)
14308c2ecf20Sopenharmony_ci{
14318c2ecf20Sopenharmony_ci	struct ar9170_calibration_target_power_legacy *ctpl;
14328c2ecf20Sopenharmony_ci	struct ar9170_calibration_target_power_ht *ctph;
14338c2ecf20Sopenharmony_ci	u8 *ctpres;
14348c2ecf20Sopenharmony_ci	int ntargets;
14358c2ecf20Sopenharmony_ci	int idx, i, n;
14368c2ecf20Sopenharmony_ci	u8 f;
14378c2ecf20Sopenharmony_ci	u8 pwr_freqs[AR5416_MAX_NUM_TGT_PWRS];
14388c2ecf20Sopenharmony_ci
14398c2ecf20Sopenharmony_ci	if (freq < 3000)
14408c2ecf20Sopenharmony_ci		f = freq - 2300;
14418c2ecf20Sopenharmony_ci	else
14428c2ecf20Sopenharmony_ci		f = (freq - 4800) / 5;
14438c2ecf20Sopenharmony_ci
14448c2ecf20Sopenharmony_ci	/*
14458c2ecf20Sopenharmony_ci	 * cycle through the various modes
14468c2ecf20Sopenharmony_ci	 *
14478c2ecf20Sopenharmony_ci	 * legacy modes first: 5G, 2G CCK, 2G OFDM
14488c2ecf20Sopenharmony_ci	 */
14498c2ecf20Sopenharmony_ci	for (i = 0; i < 3; i++) {
14508c2ecf20Sopenharmony_ci		switch (i) {
14518c2ecf20Sopenharmony_ci		case 0: /* 5 GHz legacy */
14528c2ecf20Sopenharmony_ci			ctpl = &ar->eeprom.cal_tgt_pwr_5G[0];
14538c2ecf20Sopenharmony_ci			ntargets = AR5416_NUM_5G_TARGET_PWRS;
14548c2ecf20Sopenharmony_ci			ctpres = ar->power_5G_leg;
14558c2ecf20Sopenharmony_ci			break;
14568c2ecf20Sopenharmony_ci		case 1: /* 2.4 GHz CCK */
14578c2ecf20Sopenharmony_ci			ctpl = &ar->eeprom.cal_tgt_pwr_2G_cck[0];
14588c2ecf20Sopenharmony_ci			ntargets = AR5416_NUM_2G_CCK_TARGET_PWRS;
14598c2ecf20Sopenharmony_ci			ctpres = ar->power_2G_cck;
14608c2ecf20Sopenharmony_ci			break;
14618c2ecf20Sopenharmony_ci		case 2: /* 2.4 GHz OFDM */
14628c2ecf20Sopenharmony_ci			ctpl = &ar->eeprom.cal_tgt_pwr_2G_ofdm[0];
14638c2ecf20Sopenharmony_ci			ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
14648c2ecf20Sopenharmony_ci			ctpres = ar->power_2G_ofdm;
14658c2ecf20Sopenharmony_ci			break;
14668c2ecf20Sopenharmony_ci		default:
14678c2ecf20Sopenharmony_ci			BUG();
14688c2ecf20Sopenharmony_ci		}
14698c2ecf20Sopenharmony_ci
14708c2ecf20Sopenharmony_ci		for (n = 0; n < ntargets; n++) {
14718c2ecf20Sopenharmony_ci			if (ctpl[n].freq == 0xff)
14728c2ecf20Sopenharmony_ci				break;
14738c2ecf20Sopenharmony_ci			pwr_freqs[n] = ctpl[n].freq;
14748c2ecf20Sopenharmony_ci		}
14758c2ecf20Sopenharmony_ci		ntargets = n;
14768c2ecf20Sopenharmony_ci		idx = carl9170_find_freq_idx(ntargets, pwr_freqs, f);
14778c2ecf20Sopenharmony_ci		for (n = 0; n < 4; n++)
14788c2ecf20Sopenharmony_ci			ctpres[n] = carl9170_interpolate_u8(f,
14798c2ecf20Sopenharmony_ci				ctpl[idx + 0].freq, ctpl[idx + 0].power[n],
14808c2ecf20Sopenharmony_ci				ctpl[idx + 1].freq, ctpl[idx + 1].power[n]);
14818c2ecf20Sopenharmony_ci	}
14828c2ecf20Sopenharmony_ci
14838c2ecf20Sopenharmony_ci	/* HT modes now: 5G HT20, 5G HT40, 2G CCK, 2G OFDM, 2G HT20, 2G HT40 */
14848c2ecf20Sopenharmony_ci	for (i = 0; i < 4; i++) {
14858c2ecf20Sopenharmony_ci		switch (i) {
14868c2ecf20Sopenharmony_ci		case 0: /* 5 GHz HT 20 */
14878c2ecf20Sopenharmony_ci			ctph = &ar->eeprom.cal_tgt_pwr_5G_ht20[0];
14888c2ecf20Sopenharmony_ci			ntargets = AR5416_NUM_5G_TARGET_PWRS;
14898c2ecf20Sopenharmony_ci			ctpres = ar->power_5G_ht20;
14908c2ecf20Sopenharmony_ci			break;
14918c2ecf20Sopenharmony_ci		case 1: /* 5 GHz HT 40 */
14928c2ecf20Sopenharmony_ci			ctph = &ar->eeprom.cal_tgt_pwr_5G_ht40[0];
14938c2ecf20Sopenharmony_ci			ntargets = AR5416_NUM_5G_TARGET_PWRS;
14948c2ecf20Sopenharmony_ci			ctpres = ar->power_5G_ht40;
14958c2ecf20Sopenharmony_ci			break;
14968c2ecf20Sopenharmony_ci		case 2: /* 2.4 GHz HT 20 */
14978c2ecf20Sopenharmony_ci			ctph = &ar->eeprom.cal_tgt_pwr_2G_ht20[0];
14988c2ecf20Sopenharmony_ci			ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
14998c2ecf20Sopenharmony_ci			ctpres = ar->power_2G_ht20;
15008c2ecf20Sopenharmony_ci			break;
15018c2ecf20Sopenharmony_ci		case 3: /* 2.4 GHz HT 40 */
15028c2ecf20Sopenharmony_ci			ctph = &ar->eeprom.cal_tgt_pwr_2G_ht40[0];
15038c2ecf20Sopenharmony_ci			ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
15048c2ecf20Sopenharmony_ci			ctpres = ar->power_2G_ht40;
15058c2ecf20Sopenharmony_ci			break;
15068c2ecf20Sopenharmony_ci		default:
15078c2ecf20Sopenharmony_ci			BUG();
15088c2ecf20Sopenharmony_ci		}
15098c2ecf20Sopenharmony_ci
15108c2ecf20Sopenharmony_ci		for (n = 0; n < ntargets; n++) {
15118c2ecf20Sopenharmony_ci			if (ctph[n].freq == 0xff)
15128c2ecf20Sopenharmony_ci				break;
15138c2ecf20Sopenharmony_ci			pwr_freqs[n] = ctph[n].freq;
15148c2ecf20Sopenharmony_ci		}
15158c2ecf20Sopenharmony_ci		ntargets = n;
15168c2ecf20Sopenharmony_ci		idx = carl9170_find_freq_idx(ntargets, pwr_freqs, f);
15178c2ecf20Sopenharmony_ci		for (n = 0; n < 8; n++)
15188c2ecf20Sopenharmony_ci			ctpres[n] = carl9170_interpolate_u8(f,
15198c2ecf20Sopenharmony_ci				ctph[idx + 0].freq, ctph[idx + 0].power[n],
15208c2ecf20Sopenharmony_ci				ctph[idx + 1].freq, ctph[idx + 1].power[n]);
15218c2ecf20Sopenharmony_ci	}
15228c2ecf20Sopenharmony_ci
15238c2ecf20Sopenharmony_ci	/* calc. conformance test limits and apply to ar->power*[] */
15248c2ecf20Sopenharmony_ci	carl9170_calc_ctl(ar, freq, bw);
15258c2ecf20Sopenharmony_ci}
15268c2ecf20Sopenharmony_ci
15278c2ecf20Sopenharmony_ciint carl9170_get_noisefloor(struct ar9170 *ar)
15288c2ecf20Sopenharmony_ci{
15298c2ecf20Sopenharmony_ci	static const u32 phy_regs[] = {
15308c2ecf20Sopenharmony_ci		AR9170_PHY_REG_CCA, AR9170_PHY_REG_CH2_CCA,
15318c2ecf20Sopenharmony_ci		AR9170_PHY_REG_EXT_CCA, AR9170_PHY_REG_CH2_EXT_CCA };
15328c2ecf20Sopenharmony_ci	u32 phy_res[ARRAY_SIZE(phy_regs)];
15338c2ecf20Sopenharmony_ci	int err, i;
15348c2ecf20Sopenharmony_ci
15358c2ecf20Sopenharmony_ci	BUILD_BUG_ON(ARRAY_SIZE(phy_regs) != ARRAY_SIZE(ar->noise));
15368c2ecf20Sopenharmony_ci
15378c2ecf20Sopenharmony_ci	err = carl9170_read_mreg(ar, ARRAY_SIZE(phy_regs), phy_regs, phy_res);
15388c2ecf20Sopenharmony_ci	if (err)
15398c2ecf20Sopenharmony_ci		return err;
15408c2ecf20Sopenharmony_ci
15418c2ecf20Sopenharmony_ci	for (i = 0; i < 2; i++) {
15428c2ecf20Sopenharmony_ci		ar->noise[i] = sign_extend32(GET_VAL(
15438c2ecf20Sopenharmony_ci			AR9170_PHY_CCA_MIN_PWR, phy_res[i]), 8);
15448c2ecf20Sopenharmony_ci
15458c2ecf20Sopenharmony_ci		ar->noise[i + 2] = sign_extend32(GET_VAL(
15468c2ecf20Sopenharmony_ci			AR9170_PHY_EXT_CCA_MIN_PWR, phy_res[i + 2]), 8);
15478c2ecf20Sopenharmony_ci	}
15488c2ecf20Sopenharmony_ci
15498c2ecf20Sopenharmony_ci	if (ar->channel)
15508c2ecf20Sopenharmony_ci		ar->survey[ar->channel->hw_value].noise = ar->noise[0];
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_ci	return 0;
15538c2ecf20Sopenharmony_ci}
15548c2ecf20Sopenharmony_ci
15558c2ecf20Sopenharmony_cistatic enum carl9170_bw nl80211_to_carl(enum nl80211_channel_type type)
15568c2ecf20Sopenharmony_ci{
15578c2ecf20Sopenharmony_ci	switch (type) {
15588c2ecf20Sopenharmony_ci	case NL80211_CHAN_NO_HT:
15598c2ecf20Sopenharmony_ci	case NL80211_CHAN_HT20:
15608c2ecf20Sopenharmony_ci		return CARL9170_BW_20;
15618c2ecf20Sopenharmony_ci	case NL80211_CHAN_HT40MINUS:
15628c2ecf20Sopenharmony_ci		return CARL9170_BW_40_BELOW;
15638c2ecf20Sopenharmony_ci	case NL80211_CHAN_HT40PLUS:
15648c2ecf20Sopenharmony_ci		return CARL9170_BW_40_ABOVE;
15658c2ecf20Sopenharmony_ci	default:
15668c2ecf20Sopenharmony_ci		BUG();
15678c2ecf20Sopenharmony_ci	}
15688c2ecf20Sopenharmony_ci}
15698c2ecf20Sopenharmony_ci
15708c2ecf20Sopenharmony_ciint carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
15718c2ecf20Sopenharmony_ci			 enum nl80211_channel_type _bw)
15728c2ecf20Sopenharmony_ci{
15738c2ecf20Sopenharmony_ci	const struct carl9170_phy_freq_params *freqpar;
15748c2ecf20Sopenharmony_ci	struct carl9170_rf_init_result rf_res;
15758c2ecf20Sopenharmony_ci	struct carl9170_rf_init rf;
15768c2ecf20Sopenharmony_ci	u32 tmp, offs = 0, new_ht = 0;
15778c2ecf20Sopenharmony_ci	int err;
15788c2ecf20Sopenharmony_ci	enum carl9170_bw bw;
15798c2ecf20Sopenharmony_ci	struct ieee80211_channel *old_channel = NULL;
15808c2ecf20Sopenharmony_ci
15818c2ecf20Sopenharmony_ci	bw = nl80211_to_carl(_bw);
15828c2ecf20Sopenharmony_ci
15838c2ecf20Sopenharmony_ci	if (conf_is_ht(&ar->hw->conf))
15848c2ecf20Sopenharmony_ci		new_ht |= CARL9170FW_PHY_HT_ENABLE;
15858c2ecf20Sopenharmony_ci
15868c2ecf20Sopenharmony_ci	if (conf_is_ht40(&ar->hw->conf))
15878c2ecf20Sopenharmony_ci		new_ht |= CARL9170FW_PHY_HT_DYN2040;
15888c2ecf20Sopenharmony_ci
15898c2ecf20Sopenharmony_ci	/* may be NULL at first setup */
15908c2ecf20Sopenharmony_ci	if (ar->channel) {
15918c2ecf20Sopenharmony_ci		old_channel = ar->channel;
15928c2ecf20Sopenharmony_ci		ar->channel = NULL;
15938c2ecf20Sopenharmony_ci	}
15948c2ecf20Sopenharmony_ci
15958c2ecf20Sopenharmony_ci	/* cold reset BB/ADDA */
15968c2ecf20Sopenharmony_ci	err = carl9170_write_reg(ar, AR9170_PWR_REG_RESET,
15978c2ecf20Sopenharmony_ci				 AR9170_PWR_RESET_BB_COLD_RESET);
15988c2ecf20Sopenharmony_ci	if (err)
15998c2ecf20Sopenharmony_ci		return err;
16008c2ecf20Sopenharmony_ci
16018c2ecf20Sopenharmony_ci	err = carl9170_write_reg(ar, AR9170_PWR_REG_RESET, 0x0);
16028c2ecf20Sopenharmony_ci	if (err)
16038c2ecf20Sopenharmony_ci		return err;
16048c2ecf20Sopenharmony_ci
16058c2ecf20Sopenharmony_ci	err = carl9170_init_phy(ar, channel->band);
16068c2ecf20Sopenharmony_ci	if (err)
16078c2ecf20Sopenharmony_ci		return err;
16088c2ecf20Sopenharmony_ci
16098c2ecf20Sopenharmony_ci	err = carl9170_init_rf_banks_0_7(ar,
16108c2ecf20Sopenharmony_ci					 channel->band == NL80211_BAND_5GHZ);
16118c2ecf20Sopenharmony_ci	if (err)
16128c2ecf20Sopenharmony_ci		return err;
16138c2ecf20Sopenharmony_ci
16148c2ecf20Sopenharmony_ci	err = carl9170_exec_cmd(ar, CARL9170_CMD_FREQ_START, 0, NULL, 0, NULL);
16158c2ecf20Sopenharmony_ci	if (err)
16168c2ecf20Sopenharmony_ci		return err;
16178c2ecf20Sopenharmony_ci
16188c2ecf20Sopenharmony_ci	err = carl9170_write_reg(ar, AR9170_PHY_REG_HEAVY_CLIP_ENABLE,
16198c2ecf20Sopenharmony_ci				 0x200);
16208c2ecf20Sopenharmony_ci	if (err)
16218c2ecf20Sopenharmony_ci		return err;
16228c2ecf20Sopenharmony_ci
16238c2ecf20Sopenharmony_ci	err = carl9170_init_rf_bank4_pwr(ar,
16248c2ecf20Sopenharmony_ci					 channel->band == NL80211_BAND_5GHZ,
16258c2ecf20Sopenharmony_ci					 channel->center_freq, bw);
16268c2ecf20Sopenharmony_ci	if (err)
16278c2ecf20Sopenharmony_ci		return err;
16288c2ecf20Sopenharmony_ci
16298c2ecf20Sopenharmony_ci	tmp = AR9170_PHY_TURBO_FC_SINGLE_HT_LTF1 |
16308c2ecf20Sopenharmony_ci	      AR9170_PHY_TURBO_FC_HT_EN;
16318c2ecf20Sopenharmony_ci
16328c2ecf20Sopenharmony_ci	switch (bw) {
16338c2ecf20Sopenharmony_ci	case CARL9170_BW_20:
16348c2ecf20Sopenharmony_ci		break;
16358c2ecf20Sopenharmony_ci	case CARL9170_BW_40_BELOW:
16368c2ecf20Sopenharmony_ci		tmp |= AR9170_PHY_TURBO_FC_DYN2040_EN |
16378c2ecf20Sopenharmony_ci		       AR9170_PHY_TURBO_FC_SHORT_GI_40;
16388c2ecf20Sopenharmony_ci		offs = 3;
16398c2ecf20Sopenharmony_ci		break;
16408c2ecf20Sopenharmony_ci	case CARL9170_BW_40_ABOVE:
16418c2ecf20Sopenharmony_ci		tmp |= AR9170_PHY_TURBO_FC_DYN2040_EN |
16428c2ecf20Sopenharmony_ci		       AR9170_PHY_TURBO_FC_SHORT_GI_40 |
16438c2ecf20Sopenharmony_ci		       AR9170_PHY_TURBO_FC_DYN2040_PRI_CH;
16448c2ecf20Sopenharmony_ci		offs = 1;
16458c2ecf20Sopenharmony_ci		break;
16468c2ecf20Sopenharmony_ci	default:
16478c2ecf20Sopenharmony_ci		BUG();
16488c2ecf20Sopenharmony_ci		return -ENOSYS;
16498c2ecf20Sopenharmony_ci	}
16508c2ecf20Sopenharmony_ci
16518c2ecf20Sopenharmony_ci	if (ar->eeprom.tx_mask != 1)
16528c2ecf20Sopenharmony_ci		tmp |= AR9170_PHY_TURBO_FC_WALSH;
16538c2ecf20Sopenharmony_ci
16548c2ecf20Sopenharmony_ci	err = carl9170_write_reg(ar, AR9170_PHY_REG_TURBO, tmp);
16558c2ecf20Sopenharmony_ci	if (err)
16568c2ecf20Sopenharmony_ci		return err;
16578c2ecf20Sopenharmony_ci
16588c2ecf20Sopenharmony_ci	err = carl9170_set_freq_cal_data(ar, channel);
16598c2ecf20Sopenharmony_ci	if (err)
16608c2ecf20Sopenharmony_ci		return err;
16618c2ecf20Sopenharmony_ci
16628c2ecf20Sopenharmony_ci	carl9170_set_power_cal(ar, channel->center_freq, bw);
16638c2ecf20Sopenharmony_ci
16648c2ecf20Sopenharmony_ci	err = carl9170_set_mac_tpc(ar, channel);
16658c2ecf20Sopenharmony_ci	if (err)
16668c2ecf20Sopenharmony_ci		return err;
16678c2ecf20Sopenharmony_ci
16688c2ecf20Sopenharmony_ci	freqpar = carl9170_get_hw_dyn_params(channel, bw);
16698c2ecf20Sopenharmony_ci
16708c2ecf20Sopenharmony_ci	rf.ht_settings = new_ht;
16718c2ecf20Sopenharmony_ci	if (conf_is_ht40(&ar->hw->conf))
16728c2ecf20Sopenharmony_ci		SET_VAL(CARL9170FW_PHY_HT_EXT_CHAN_OFF, rf.ht_settings, offs);
16738c2ecf20Sopenharmony_ci
16748c2ecf20Sopenharmony_ci	rf.freq = cpu_to_le32(channel->center_freq * 1000);
16758c2ecf20Sopenharmony_ci	rf.delta_slope_coeff_exp = cpu_to_le32(freqpar->coeff_exp);
16768c2ecf20Sopenharmony_ci	rf.delta_slope_coeff_man = cpu_to_le32(freqpar->coeff_man);
16778c2ecf20Sopenharmony_ci	rf.delta_slope_coeff_exp_shgi = cpu_to_le32(freqpar->coeff_exp_shgi);
16788c2ecf20Sopenharmony_ci	rf.delta_slope_coeff_man_shgi = cpu_to_le32(freqpar->coeff_man_shgi);
16798c2ecf20Sopenharmony_ci	rf.finiteLoopCount = cpu_to_le32(2000);
16808c2ecf20Sopenharmony_ci	err = carl9170_exec_cmd(ar, CARL9170_CMD_RF_INIT, sizeof(rf), &rf,
16818c2ecf20Sopenharmony_ci				sizeof(rf_res), &rf_res);
16828c2ecf20Sopenharmony_ci	if (err)
16838c2ecf20Sopenharmony_ci		return err;
16848c2ecf20Sopenharmony_ci
16858c2ecf20Sopenharmony_ci	err = le32_to_cpu(rf_res.ret);
16868c2ecf20Sopenharmony_ci	if (err != 0) {
16878c2ecf20Sopenharmony_ci		ar->chan_fail++;
16888c2ecf20Sopenharmony_ci		ar->total_chan_fail++;
16898c2ecf20Sopenharmony_ci
16908c2ecf20Sopenharmony_ci		wiphy_err(ar->hw->wiphy, "channel change: %d -> %d "
16918c2ecf20Sopenharmony_ci			  "failed (%d).\n", old_channel ?
16928c2ecf20Sopenharmony_ci			  old_channel->center_freq : -1, channel->center_freq,
16938c2ecf20Sopenharmony_ci			  err);
16948c2ecf20Sopenharmony_ci
16958c2ecf20Sopenharmony_ci		if (ar->chan_fail > 3) {
16968c2ecf20Sopenharmony_ci			/* We have tried very hard to change to _another_
16978c2ecf20Sopenharmony_ci			 * channel and we've failed to do so!
16988c2ecf20Sopenharmony_ci			 * Chances are that the PHY/RF is no longer
16998c2ecf20Sopenharmony_ci			 * operable (due to corruptions/fatal events/bugs?)
17008c2ecf20Sopenharmony_ci			 * and we need to reset at a higher level.
17018c2ecf20Sopenharmony_ci			 */
17028c2ecf20Sopenharmony_ci			carl9170_restart(ar, CARL9170_RR_TOO_MANY_PHY_ERRORS);
17038c2ecf20Sopenharmony_ci			return 0;
17048c2ecf20Sopenharmony_ci		}
17058c2ecf20Sopenharmony_ci
17068c2ecf20Sopenharmony_ci		err = carl9170_set_channel(ar, channel, _bw);
17078c2ecf20Sopenharmony_ci		if (err)
17088c2ecf20Sopenharmony_ci			return err;
17098c2ecf20Sopenharmony_ci	} else {
17108c2ecf20Sopenharmony_ci		ar->chan_fail = 0;
17118c2ecf20Sopenharmony_ci	}
17128c2ecf20Sopenharmony_ci
17138c2ecf20Sopenharmony_ci	if (ar->heavy_clip) {
17148c2ecf20Sopenharmony_ci		err = carl9170_write_reg(ar, AR9170_PHY_REG_HEAVY_CLIP_ENABLE,
17158c2ecf20Sopenharmony_ci					 0x200 | ar->heavy_clip);
17168c2ecf20Sopenharmony_ci		if (err) {
17178c2ecf20Sopenharmony_ci			if (net_ratelimit()) {
17188c2ecf20Sopenharmony_ci				wiphy_err(ar->hw->wiphy, "failed to set "
17198c2ecf20Sopenharmony_ci				       "heavy clip\n");
17208c2ecf20Sopenharmony_ci			}
17218c2ecf20Sopenharmony_ci
17228c2ecf20Sopenharmony_ci			return err;
17238c2ecf20Sopenharmony_ci		}
17248c2ecf20Sopenharmony_ci	}
17258c2ecf20Sopenharmony_ci
17268c2ecf20Sopenharmony_ci	ar->channel = channel;
17278c2ecf20Sopenharmony_ci	ar->ht_settings = new_ht;
17288c2ecf20Sopenharmony_ci	return 0;
17298c2ecf20Sopenharmony_ci}
1730