18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci Broadcom B43 wireless driver 48c2ecf20Sopenharmony_ci IEEE 802.11n LCN-PHY support 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com> 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, write to 208c2ecf20Sopenharmony_ci the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, 218c2ecf20Sopenharmony_ci Boston, MA 02110-1301, USA. 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci This file incorporates work covered by the following copyright and 248c2ecf20Sopenharmony_ci permission notice: 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci Copyright (c) 2010 Broadcom Corporation 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci Permission to use, copy, modify, and/or distribute this software for any 298c2ecf20Sopenharmony_ci purpose with or without fee is hereby granted, provided that the above 308c2ecf20Sopenharmony_ci copyright notice and this permission notice appear in all copies. 318c2ecf20Sopenharmony_ci*/ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include <linux/slab.h> 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include "b43.h" 368c2ecf20Sopenharmony_ci#include "phy_lcn.h" 378c2ecf20Sopenharmony_ci#include "tables_phy_lcn.h" 388c2ecf20Sopenharmony_ci#include "main.h" 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct lcn_tx_gains { 418c2ecf20Sopenharmony_ci u16 gm_gain; 428c2ecf20Sopenharmony_ci u16 pga_gain; 438c2ecf20Sopenharmony_ci u16 pad_gain; 448c2ecf20Sopenharmony_ci u16 dac_gain; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistruct lcn_tx_iir_filter { 488c2ecf20Sopenharmony_ci u8 type; 498c2ecf20Sopenharmony_ci u16 values[16]; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cienum lcn_sense_type { 538c2ecf20Sopenharmony_ci B43_SENSE_TEMP, 548c2ecf20Sopenharmony_ci B43_SENSE_VBAT, 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/************************************************** 588c2ecf20Sopenharmony_ci * Radio 2064. 598c2ecf20Sopenharmony_ci **************************************************/ 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/* wlc_lcnphy_radio_2064_channel_tune_4313 */ 628c2ecf20Sopenharmony_cistatic void b43_radio_2064_channel_setup(struct b43_wldev *dev) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci u16 save[2]; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x09d, 0x4); 678c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x09e, 0xf); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci /* Channel specific values in theory, in practice always the same */ 708c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x02a, 0xb); 718c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x030, ~0x3, 0xa); 728c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x091, ~0x3, 0); 738c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x038, ~0xf, 0x7); 748c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x030, ~0xc, 0x8); 758c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x05e, ~0xf, 0x8); 768c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x05e, ~0xf0, 0x80); 778c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x06c, 0x80); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci save[0] = b43_radio_read(dev, 0x044); 808c2ecf20Sopenharmony_ci save[1] = b43_radio_read(dev, 0x12b); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x044, 0x7); 838c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x12b, 0xe); 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci /* TODO */ 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x040, 0xfb); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x041, 0x9a); 908c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x042, 0xa3); 918c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x043, 0x0c); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci /* TODO */ 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x044, 0x0c); 968c2ecf20Sopenharmony_ci udelay(1); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x044, save[0]); 998c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x12b, save[1]); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci if (dev->phy.rev == 1) { 1028c2ecf20Sopenharmony_ci /* brcmsmac uses outdated 0x3 for 0x038 */ 1038c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x038, 0x0); 1048c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x091, 0x7); 1058c2ecf20Sopenharmony_ci } 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/* wlc_radio_2064_init */ 1098c2ecf20Sopenharmony_cistatic void b43_radio_2064_init(struct b43_wldev *dev) 1108c2ecf20Sopenharmony_ci{ 1118c2ecf20Sopenharmony_ci if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) { 1128c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x09c, 0x0020); 1138c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x105, 0x0008); 1148c2ecf20Sopenharmony_ci } else { 1158c2ecf20Sopenharmony_ci /* TODO */ 1168c2ecf20Sopenharmony_ci } 1178c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x032, 0x0062); 1188c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x033, 0x0019); 1198c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x090, 0x0010); 1208c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x010, 0x0000); 1218c2ecf20Sopenharmony_ci if (dev->phy.rev == 1) { 1228c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x060, 0x007f); 1238c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x061, 0x0072); 1248c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x062, 0x007f); 1258c2ecf20Sopenharmony_ci } 1268c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x01d, 0x0002); 1278c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x01e, 0x0006); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x4ea, 0x4688); 1308c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4eb, ~0x7, 0x2); 1318c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x4eb, ~0x01c0); 1328c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x46a, 0xff00, 0x19); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci b43_lcntab_write(dev, B43_LCNTAB16(0x00, 0x55), 0); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci b43_radio_mask(dev, 0x05b, (u16) ~0xff02); 1378c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x004, 0x40); 1388c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x120, 0x10); 1398c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x078, 0x80); 1408c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x129, 0x2); 1418c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x057, 0x1); 1428c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x05b, 0x2); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci /* TODO: wait for some bit to be set */ 1458c2ecf20Sopenharmony_ci b43_radio_read(dev, 0x05c); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci b43_radio_mask(dev, 0x05b, (u16) ~0xff02); 1488c2ecf20Sopenharmony_ci b43_radio_mask(dev, 0x057, (u16) ~0xff01); 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x933, 0x2d6b); 1518c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x934, 0x2d6b); 1528c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x935, 0x2d6b); 1538c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x936, 0x2d6b); 1548c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x937, 0x016b); 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci b43_radio_mask(dev, 0x057, (u16) ~0xff02); 1578c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x0c2, 0x006f); 1588c2ecf20Sopenharmony_ci} 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/************************************************** 1618c2ecf20Sopenharmony_ci * Various PHY ops 1628c2ecf20Sopenharmony_ci **************************************************/ 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci/* wlc_lcnphy_toggle_afe_pwdn */ 1658c2ecf20Sopenharmony_cistatic void b43_phy_lcn_afe_set_unset(struct b43_wldev *dev) 1668c2ecf20Sopenharmony_ci{ 1678c2ecf20Sopenharmony_ci u16 afe_ctl2 = b43_phy_read(dev, B43_PHY_LCN_AFE_CTL2); 1688c2ecf20Sopenharmony_ci u16 afe_ctl1 = b43_phy_read(dev, B43_PHY_LCN_AFE_CTL1); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2 | 0x1); 1718c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1 | 0x1); 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2 & ~0x1); 1748c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1 & ~0x1); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2); 1778c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1); 1788c2ecf20Sopenharmony_ci} 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci/* wlc_lcnphy_get_pa_gain */ 1818c2ecf20Sopenharmony_cistatic u16 b43_phy_lcn_get_pa_gain(struct b43_wldev *dev) 1828c2ecf20Sopenharmony_ci{ 1838c2ecf20Sopenharmony_ci return (b43_phy_read(dev, 0x4fb) & 0x7f00) >> 8; 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/* wlc_lcnphy_set_dac_gain */ 1878c2ecf20Sopenharmony_cistatic void b43_phy_lcn_set_dac_gain(struct b43_wldev *dev, u16 dac_gain) 1888c2ecf20Sopenharmony_ci{ 1898c2ecf20Sopenharmony_ci u16 dac_ctrl; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci dac_ctrl = b43_phy_read(dev, 0x439); 1928c2ecf20Sopenharmony_ci dac_ctrl = dac_ctrl & 0xc7f; 1938c2ecf20Sopenharmony_ci dac_ctrl = dac_ctrl | (dac_gain << 7); 1948c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x439, ~0xfff, dac_ctrl); 1958c2ecf20Sopenharmony_ci} 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci/* wlc_lcnphy_set_bbmult */ 1988c2ecf20Sopenharmony_cistatic void b43_phy_lcn_set_bbmult(struct b43_wldev *dev, u8 m0) 1998c2ecf20Sopenharmony_ci{ 2008c2ecf20Sopenharmony_ci b43_lcntab_write(dev, B43_LCNTAB16(0x00, 0x57), m0 << 8); 2018c2ecf20Sopenharmony_ci} 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci/* wlc_lcnphy_clear_tx_power_offsets */ 2048c2ecf20Sopenharmony_cistatic void b43_phy_lcn_clear_tx_power_offsets(struct b43_wldev *dev) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci u8 i; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci if (1) { /* FIXME */ 2098c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_TABLE_ADDR, (0x7 << 10) | 0x340); 2108c2ecf20Sopenharmony_ci for (i = 0; i < 30; i++) { 2118c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_TABLE_DATAHI, 0); 2128c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_TABLE_DATALO, 0); 2138c2ecf20Sopenharmony_ci } 2148c2ecf20Sopenharmony_ci } 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_TABLE_ADDR, (0x7 << 10) | 0x80); 2178c2ecf20Sopenharmony_ci for (i = 0; i < 64; i++) { 2188c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_TABLE_DATAHI, 0); 2198c2ecf20Sopenharmony_ci b43_phy_write(dev, B43_PHY_LCN_TABLE_DATALO, 0); 2208c2ecf20Sopenharmony_ci } 2218c2ecf20Sopenharmony_ci} 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci/* wlc_lcnphy_rev0_baseband_init */ 2248c2ecf20Sopenharmony_cistatic void b43_phy_lcn_rev0_baseband_init(struct b43_wldev *dev) 2258c2ecf20Sopenharmony_ci{ 2268c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x11c, 0); 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x43b, 0); 2298c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x43c, 0); 2308c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x44c, 0); 2318c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x4e6, 0); 2328c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x4f9, 0); 2338c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x4b0, 0); 2348c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x938, 0); 2358c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x4b0, 0); 2368c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x44e, 0); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x567, 0x03); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x44a, 0x44); 2418c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x44a, 0x80); 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci if (!(dev->dev->bus_sprom->boardflags_lo & B43_BFL_FEM)) 2448c2ecf20Sopenharmony_ci ; /* TODO */ 2458c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x634, ~0xff, 0xc); 2468c2ecf20Sopenharmony_ci if (dev->dev->bus_sprom->boardflags_lo & B43_BFL_FEM) { 2478c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x634, ~0xff, 0xa); 2488c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x910, 0x1); 2498c2ecf20Sopenharmony_ci } 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x910, 0x1); 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x448, ~0x300, 0x100); 2548c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x608, ~0xff, 0x17); 2558c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x604, ~0x7ff, 0x3ea); 2568c2ecf20Sopenharmony_ci} 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci/* wlc_lcnphy_bu_tweaks */ 2598c2ecf20Sopenharmony_cistatic void b43_phy_lcn_bu_tweaks(struct b43_wldev *dev) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x805, 0x1); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x42f, ~0x7, 0x3); 2648c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x030, ~0x7, 0x3); 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x414, 0x1e10); 2678c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x415, 0x0640); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4df, (u16) ~0xff00, 0xf700); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x44a, 0x44); 2728c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x44a, 0x80); 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x434, ~0xff, 0xfd); 2758c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x420, ~0xff, 0x10); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci if (dev->dev->bus_sprom->board_rev >= 0x1204) 2788c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x09b, 0xf0); 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x7d6, 0x0902); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x429, ~0xf, 0x9); 2838c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x429, ~(0x3f << 4), 0xe << 4); 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci if (dev->phy.rev == 1) { 2868c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x423, ~0xff, 0x46); 2878c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x411, ~0xff, 1); 2888c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x434, 0xff); /* FIXME: update to wl */ 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci /* TODO: wl operates on PHY 0x416, brcmsmac is outdated here */ 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x656, ~0xf, 2); 2938c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x44d, 4); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x0f7, 0x4); 2968c2ecf20Sopenharmony_ci b43_radio_mask(dev, 0x0f1, ~0x3); 2978c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x0f2, ~0xf8, 0x90); 2988c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x0f3, ~0x3, 0x2); 2998c2ecf20Sopenharmony_ci b43_radio_maskset(dev, 0x0f3, ~0xf0, 0xa0); 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x11f, 0x2); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci b43_phy_lcn_clear_tx_power_offsets(dev); 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci /* TODO: something more? */ 3068c2ecf20Sopenharmony_ci } 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci/* wlc_lcnphy_vbat_temp_sense_setup */ 3108c2ecf20Sopenharmony_cistatic void b43_phy_lcn_sense_setup(struct b43_wldev *dev, 3118c2ecf20Sopenharmony_ci enum lcn_sense_type sense_type) 3128c2ecf20Sopenharmony_ci{ 3138c2ecf20Sopenharmony_ci u8 auxpga_vmidcourse, auxpga_vmidfine, auxpga_gain; 3148c2ecf20Sopenharmony_ci u16 auxpga_vmid; 3158c2ecf20Sopenharmony_ci u8 tx_pwr_idx; 3168c2ecf20Sopenharmony_ci u8 i; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci u16 save_radio_regs[6][2] = { 3198c2ecf20Sopenharmony_ci { 0x007, 0 }, { 0x0ff, 0 }, { 0x11f, 0 }, { 0x005, 0 }, 3208c2ecf20Sopenharmony_ci { 0x025, 0 }, { 0x112, 0 }, 3218c2ecf20Sopenharmony_ci }; 3228c2ecf20Sopenharmony_ci u16 save_phy_regs[14][2] = { 3238c2ecf20Sopenharmony_ci { 0x503, 0 }, { 0x4a4, 0 }, { 0x4d0, 0 }, { 0x4d9, 0 }, 3248c2ecf20Sopenharmony_ci { 0x4da, 0 }, { 0x4a6, 0 }, { 0x938, 0 }, { 0x939, 0 }, 3258c2ecf20Sopenharmony_ci { 0x4d8, 0 }, { 0x4d0, 0 }, { 0x4d7, 0 }, { 0x4a5, 0 }, 3268c2ecf20Sopenharmony_ci { 0x40d, 0 }, { 0x4a2, 0 }, 3278c2ecf20Sopenharmony_ci }; 3288c2ecf20Sopenharmony_ci u16 save_radio_4a4; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci msleep(1); 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci /* Save */ 3338c2ecf20Sopenharmony_ci for (i = 0; i < 6; i++) 3348c2ecf20Sopenharmony_ci save_radio_regs[i][1] = b43_radio_read(dev, 3358c2ecf20Sopenharmony_ci save_radio_regs[i][0]); 3368c2ecf20Sopenharmony_ci for (i = 0; i < 14; i++) 3378c2ecf20Sopenharmony_ci save_phy_regs[i][1] = b43_phy_read(dev, save_phy_regs[i][0]); 3388c2ecf20Sopenharmony_ci b43_mac_suspend(dev); 3398c2ecf20Sopenharmony_ci save_radio_4a4 = b43_radio_read(dev, 0x4a4); 3408c2ecf20Sopenharmony_ci /* wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF); */ 3418c2ecf20Sopenharmony_ci tx_pwr_idx = dev->phy.lcn->tx_pwr_curr_idx; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci /* Setup */ 3448c2ecf20Sopenharmony_ci /* TODO: wlc_lcnphy_set_tx_pwr_by_index(pi, 127); */ 3458c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x007, 0x1); 3468c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x0ff, 0x10); 3478c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x11f, 0x4); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x503, ~0x1); 3508c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x503, ~0x4); 3518c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x4a4, ~0x4000); 3528c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x4a4, (u16) ~0x8000); 3538c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x4d0, ~0x20); 3548c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4a5, 0xff); 3558c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4a5, ~0x7000, 0x5000); 3568c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x4a5, ~0x700); 3578c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x40d, ~0xff, 64); 3588c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x40d, ~0x700, 0x600); 3598c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4a2, ~0xff, 64); 3608c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4a2, ~0x700, 0x600); 3618c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4d9, ~0x70, 0x20); 3628c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4d9, ~0x700, 0x300); 3638c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4d9, ~0x7000, 0x1000); 3648c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x4da, ~0x1000); 3658c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4da, 0x2000); 3668c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4a6, 0x8000); 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x025, 0xc); 3698c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x005, 0x8); 3708c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x938, 0x4); 3718c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x939, 0x4); 3728c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4a4, 0x1000); 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci /* FIXME: don't hardcode */ 3758c2ecf20Sopenharmony_ci b43_lcntab_write(dev, B43_LCNTAB16(0x8, 0x6), 0x640); 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci switch (sense_type) { 3788c2ecf20Sopenharmony_ci case B43_SENSE_TEMP: 3798c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4d7, 0x8); 3808c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4d7, ~0x7000, 0x1000); 3818c2ecf20Sopenharmony_ci auxpga_vmidcourse = 8; 3828c2ecf20Sopenharmony_ci auxpga_vmidfine = 0x4; 3838c2ecf20Sopenharmony_ci auxpga_gain = 2; 3848c2ecf20Sopenharmony_ci b43_radio_set(dev, 0x082, 0x20); 3858c2ecf20Sopenharmony_ci break; 3868c2ecf20Sopenharmony_ci case B43_SENSE_VBAT: 3878c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4d7, 0x8); 3888c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4d7, ~0x7000, 0x3000); 3898c2ecf20Sopenharmony_ci auxpga_vmidcourse = 7; 3908c2ecf20Sopenharmony_ci auxpga_vmidfine = 0xa; 3918c2ecf20Sopenharmony_ci auxpga_gain = 2; 3928c2ecf20Sopenharmony_ci break; 3938c2ecf20Sopenharmony_ci } 3948c2ecf20Sopenharmony_ci auxpga_vmid = (0x200 | (auxpga_vmidcourse << 4) | auxpga_vmidfine); 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4d8, 0x1); 3978c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4d8, ~(0x3ff << 2), auxpga_vmid << 2); 3988c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4d8, 0x2); 3998c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4d8, ~(0x7 << 12), auxpga_gain << 12); 4008c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x4d0, 0x20); 4018c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x112, 0x6); 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci b43_dummy_transmission(dev, true, false); 4048c2ecf20Sopenharmony_ci /* Wait if not done */ 4058c2ecf20Sopenharmony_ci if (!(b43_phy_read(dev, 0x476) & 0x8000)) 4068c2ecf20Sopenharmony_ci udelay(10); 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci /* Restore */ 4098c2ecf20Sopenharmony_ci for (i = 0; i < 6; i++) 4108c2ecf20Sopenharmony_ci b43_radio_write(dev, save_radio_regs[i][0], 4118c2ecf20Sopenharmony_ci save_radio_regs[i][1]); 4128c2ecf20Sopenharmony_ci for (i = 0; i < 14; i++) 4138c2ecf20Sopenharmony_ci b43_phy_write(dev, save_phy_regs[i][0], save_phy_regs[i][1]); 4148c2ecf20Sopenharmony_ci /* TODO: wlc_lcnphy_set_tx_pwr_by_index(tx_pwr_idx) */ 4158c2ecf20Sopenharmony_ci b43_radio_write(dev, 0x4a4, save_radio_4a4); 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci b43_mac_enable(dev); 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci msleep(1); 4208c2ecf20Sopenharmony_ci} 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistatic bool b43_phy_lcn_load_tx_iir_cck_filter(struct b43_wldev *dev, 4238c2ecf20Sopenharmony_ci u8 filter_type) 4248c2ecf20Sopenharmony_ci{ 4258c2ecf20Sopenharmony_ci int i, j; 4268c2ecf20Sopenharmony_ci u16 phy_regs[] = { 0x910, 0x91e, 0x91f, 0x924, 0x925, 0x926, 0x920, 4278c2ecf20Sopenharmony_ci 0x921, 0x927, 0x928, 0x929, 0x922, 0x923, 0x930, 4288c2ecf20Sopenharmony_ci 0x931, 0x932 }; 4298c2ecf20Sopenharmony_ci /* Table is from brcmsmac, values for type 25 were outdated, probably 4308c2ecf20Sopenharmony_ci * others need updating too */ 4318c2ecf20Sopenharmony_ci struct lcn_tx_iir_filter tx_iir_filters_cck[] = { 4328c2ecf20Sopenharmony_ci { 0, { 1, 415, 1874, 64, 128, 64, 792, 1656, 64, 128, 64, 778, 4338c2ecf20Sopenharmony_ci 1582, 64, 128, 64 } }, 4348c2ecf20Sopenharmony_ci { 1, { 1, 402, 1847, 259, 59, 259, 671, 1794, 68, 54, 68, 608, 4358c2ecf20Sopenharmony_ci 1863, 93, 167, 93 } }, 4368c2ecf20Sopenharmony_ci { 2, { 1, 415, 1874, 64, 128, 64, 792, 1656, 192, 384, 192, 4378c2ecf20Sopenharmony_ci 778, 1582, 64, 128, 64 } }, 4388c2ecf20Sopenharmony_ci { 3, { 1, 302, 1841, 129, 258, 129, 658, 1720, 205, 410, 205, 4398c2ecf20Sopenharmony_ci 754, 1760, 170, 340, 170 } }, 4408c2ecf20Sopenharmony_ci { 20, { 1, 360, 1884, 242, 1734, 242, 752, 1720, 205, 1845, 205, 4418c2ecf20Sopenharmony_ci 767, 1760, 256, 185, 256 } }, 4428c2ecf20Sopenharmony_ci { 21, { 1, 360, 1884, 149, 1874, 149, 752, 1720, 205, 1883, 205, 4438c2ecf20Sopenharmony_ci 767, 1760, 256, 273, 256 } }, 4448c2ecf20Sopenharmony_ci { 22, { 1, 360, 1884, 98, 1948, 98, 752, 1720, 205, 1924, 205, 4458c2ecf20Sopenharmony_ci 767, 1760, 256, 352, 256 } }, 4468c2ecf20Sopenharmony_ci { 23, { 1, 350, 1884, 116, 1966, 116, 752, 1720, 205, 2008, 205, 4478c2ecf20Sopenharmony_ci 767, 1760, 128, 233, 128 } }, 4488c2ecf20Sopenharmony_ci { 24, { 1, 325, 1884, 32, 40, 32, 756, 1720, 256, 471, 256, 766, 4498c2ecf20Sopenharmony_ci 1760, 256, 1881, 256 } }, 4508c2ecf20Sopenharmony_ci { 25, { 1, 299, 1884, 51, 64, 51, 736, 1720, 256, 471, 256, 765, 4518c2ecf20Sopenharmony_ci 1760, 262, 1878, 262 } }, 4528c2ecf20Sopenharmony_ci /* brcmsmac version { 25, { 1, 299, 1884, 51, 64, 51, 736, 1720, 4538c2ecf20Sopenharmony_ci * 256, 471, 256, 765, 1760, 256, 1881, 256 } }, */ 4548c2ecf20Sopenharmony_ci { 26, { 1, 277, 1943, 39, 117, 88, 637, 1838, 64, 192, 144, 614, 4558c2ecf20Sopenharmony_ci 1864, 128, 384, 288 } }, 4568c2ecf20Sopenharmony_ci { 27, { 1, 245, 1943, 49, 147, 110, 626, 1838, 256, 768, 576, 4578c2ecf20Sopenharmony_ci 613, 1864, 128, 384, 288 } }, 4588c2ecf20Sopenharmony_ci { 30, { 1, 302, 1841, 61, 122, 61, 658, 1720, 205, 410, 205, 4598c2ecf20Sopenharmony_ci 754, 1760, 170, 340, 170 } }, 4608c2ecf20Sopenharmony_ci }; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(tx_iir_filters_cck); i++) { 4638c2ecf20Sopenharmony_ci if (tx_iir_filters_cck[i].type == filter_type) { 4648c2ecf20Sopenharmony_ci for (j = 0; j < 16; j++) 4658c2ecf20Sopenharmony_ci b43_phy_write(dev, phy_regs[j], 4668c2ecf20Sopenharmony_ci tx_iir_filters_cck[i].values[j]); 4678c2ecf20Sopenharmony_ci return true; 4688c2ecf20Sopenharmony_ci } 4698c2ecf20Sopenharmony_ci } 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci return false; 4728c2ecf20Sopenharmony_ci} 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_cistatic bool b43_phy_lcn_load_tx_iir_ofdm_filter(struct b43_wldev *dev, 4758c2ecf20Sopenharmony_ci u8 filter_type) 4768c2ecf20Sopenharmony_ci{ 4778c2ecf20Sopenharmony_ci int i, j; 4788c2ecf20Sopenharmony_ci u16 phy_regs[] = { 0x90f, 0x900, 0x901, 0x906, 0x907, 0x908, 0x902, 4798c2ecf20Sopenharmony_ci 0x903, 0x909, 0x90a, 0x90b, 0x904, 0x905, 0x90c, 4808c2ecf20Sopenharmony_ci 0x90d, 0x90e }; 4818c2ecf20Sopenharmony_ci struct lcn_tx_iir_filter tx_iir_filters_ofdm[] = { 4828c2ecf20Sopenharmony_ci { 0, { 0, 0xa2, 0x0, 0x100, 0x100, 0x0, 0x0, 0x0, 0x100, 0x0, 4838c2ecf20Sopenharmony_ci 0x0, 0x278, 0xfea0, 0x80, 0x100, 0x80 } }, 4848c2ecf20Sopenharmony_ci { 1, { 0, 374, 0xFF79, 16, 32, 16, 799, 0xFE74, 50, 32, 50, 750, 4858c2ecf20Sopenharmony_ci 0xFE2B, 212, 0xFFCE, 212 } }, 4868c2ecf20Sopenharmony_ci { 2, { 0, 375, 0xFF16, 37, 76, 37, 799, 0xFE74, 32, 20, 32, 748, 4878c2ecf20Sopenharmony_ci 0xFEF2, 128, 0xFFE2, 128 } }, 4888c2ecf20Sopenharmony_ci }; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(tx_iir_filters_ofdm); i++) { 4918c2ecf20Sopenharmony_ci if (tx_iir_filters_ofdm[i].type == filter_type) { 4928c2ecf20Sopenharmony_ci for (j = 0; j < 16; j++) 4938c2ecf20Sopenharmony_ci b43_phy_write(dev, phy_regs[j], 4948c2ecf20Sopenharmony_ci tx_iir_filters_ofdm[i].values[j]); 4958c2ecf20Sopenharmony_ci return true; 4968c2ecf20Sopenharmony_ci } 4978c2ecf20Sopenharmony_ci } 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci return false; 5008c2ecf20Sopenharmony_ci} 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci/* wlc_lcnphy_set_tx_gain_override */ 5038c2ecf20Sopenharmony_cistatic void b43_phy_lcn_set_tx_gain_override(struct b43_wldev *dev, bool enable) 5048c2ecf20Sopenharmony_ci{ 5058c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4b0, ~(0x1 << 7), enable << 7); 5068c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4b0, ~(0x1 << 14), enable << 14); 5078c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x43b, ~(0x1 << 6), enable << 6); 5088c2ecf20Sopenharmony_ci} 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci/* wlc_lcnphy_set_tx_gain */ 5118c2ecf20Sopenharmony_cistatic void b43_phy_lcn_set_tx_gain(struct b43_wldev *dev, 5128c2ecf20Sopenharmony_ci struct lcn_tx_gains *target_gains) 5138c2ecf20Sopenharmony_ci{ 5148c2ecf20Sopenharmony_ci u16 pa_gain = b43_phy_lcn_get_pa_gain(dev); 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x4b5, 5178c2ecf20Sopenharmony_ci (target_gains->gm_gain | (target_gains->pga_gain << 8))); 5188c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4fb, ~0x7fff, 5198c2ecf20Sopenharmony_ci (target_gains->pad_gain | (pa_gain << 8))); 5208c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x4fc, 5218c2ecf20Sopenharmony_ci (target_gains->gm_gain | (target_gains->pga_gain << 8))); 5228c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4fd, ~0x7fff, 5238c2ecf20Sopenharmony_ci (target_gains->pad_gain | (pa_gain << 8))); 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci b43_phy_lcn_set_dac_gain(dev, target_gains->dac_gain); 5268c2ecf20Sopenharmony_ci b43_phy_lcn_set_tx_gain_override(dev, true); 5278c2ecf20Sopenharmony_ci} 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci/* wlc_lcnphy_tx_pwr_ctrl_init */ 5308c2ecf20Sopenharmony_cistatic void b43_phy_lcn_tx_pwr_ctl_init(struct b43_wldev *dev) 5318c2ecf20Sopenharmony_ci{ 5328c2ecf20Sopenharmony_ci struct lcn_tx_gains tx_gains; 5338c2ecf20Sopenharmony_ci u8 bbmult; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci b43_mac_suspend(dev); 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci if (!dev->phy.lcn->hw_pwr_ctl_capable) { 5388c2ecf20Sopenharmony_ci if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) { 5398c2ecf20Sopenharmony_ci tx_gains.gm_gain = 4; 5408c2ecf20Sopenharmony_ci tx_gains.pga_gain = 12; 5418c2ecf20Sopenharmony_ci tx_gains.pad_gain = 12; 5428c2ecf20Sopenharmony_ci tx_gains.dac_gain = 0; 5438c2ecf20Sopenharmony_ci bbmult = 150; 5448c2ecf20Sopenharmony_ci } else { 5458c2ecf20Sopenharmony_ci tx_gains.gm_gain = 7; 5468c2ecf20Sopenharmony_ci tx_gains.pga_gain = 15; 5478c2ecf20Sopenharmony_ci tx_gains.pad_gain = 14; 5488c2ecf20Sopenharmony_ci tx_gains.dac_gain = 0; 5498c2ecf20Sopenharmony_ci bbmult = 150; 5508c2ecf20Sopenharmony_ci } 5518c2ecf20Sopenharmony_ci b43_phy_lcn_set_tx_gain(dev, &tx_gains); 5528c2ecf20Sopenharmony_ci b43_phy_lcn_set_bbmult(dev, bbmult); 5538c2ecf20Sopenharmony_ci b43_phy_lcn_sense_setup(dev, B43_SENSE_TEMP); 5548c2ecf20Sopenharmony_ci } else { 5558c2ecf20Sopenharmony_ci b43err(dev->wl, "TX power control not supported for this HW\n"); 5568c2ecf20Sopenharmony_ci } 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci b43_mac_enable(dev); 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci/* wlc_lcnphy_txrx_spur_avoidance_mode */ 5628c2ecf20Sopenharmony_cistatic void b43_phy_lcn_txrx_spur_avoidance_mode(struct b43_wldev *dev, 5638c2ecf20Sopenharmony_ci bool enable) 5648c2ecf20Sopenharmony_ci{ 5658c2ecf20Sopenharmony_ci if (enable) { 5668c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x942, 0x7); 5678c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x93b, ((1 << 13) + 23)); 5688c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x93c, ((1 << 13) + 1989)); 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x44a, 0x084); 5718c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x44a, 0x080); 5728c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x6d3, 0x2222); 5738c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x6d3, 0x2220); 5748c2ecf20Sopenharmony_ci } else { 5758c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x942, 0x0); 5768c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x93b, ((0 << 13) + 23)); 5778c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x93c, ((0 << 13) + 1989)); 5788c2ecf20Sopenharmony_ci } 5798c2ecf20Sopenharmony_ci b43_mac_switch_freq(dev, enable); 5808c2ecf20Sopenharmony_ci} 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci/************************************************** 5838c2ecf20Sopenharmony_ci * Channel switching ops. 5848c2ecf20Sopenharmony_ci **************************************************/ 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci/* wlc_lcnphy_set_chanspec_tweaks */ 5878c2ecf20Sopenharmony_cistatic void b43_phy_lcn_set_channel_tweaks(struct b43_wldev *dev, int channel) 5888c2ecf20Sopenharmony_ci{ 5898c2ecf20Sopenharmony_ci struct bcma_drv_cc *cc = &dev->dev->bdev->bus->drv_cc; 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x448, ~0x300, (channel == 14) ? 0x200 : 0x100); 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci if (channel == 1 || channel == 2 || channel == 3 || channel == 4 || 5948c2ecf20Sopenharmony_ci channel == 9 || channel == 10 || channel == 11 || channel == 12) { 5958c2ecf20Sopenharmony_ci bcma_chipco_pll_write(cc, 0x2, 0x03000c04); 5968c2ecf20Sopenharmony_ci bcma_chipco_pll_maskset(cc, 0x3, 0x00ffffff, 0x0); 5978c2ecf20Sopenharmony_ci bcma_chipco_pll_write(cc, 0x4, 0x200005c0); 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci bcma_cc_set32(cc, BCMA_CC_PMU_CTL, 0x400); 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x942, 0); 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci b43_phy_lcn_txrx_spur_avoidance_mode(dev, false); 6048c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x424, (u16) ~0xff00, 0x1b00); 6058c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x425, 0x5907); 6068c2ecf20Sopenharmony_ci } else { 6078c2ecf20Sopenharmony_ci bcma_chipco_pll_write(cc, 0x2, 0x03140c04); 6088c2ecf20Sopenharmony_ci bcma_chipco_pll_maskset(cc, 0x3, 0x00ffffff, 0x333333); 6098c2ecf20Sopenharmony_ci bcma_chipco_pll_write(cc, 0x4, 0x202c2820); 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci bcma_cc_set32(cc, BCMA_CC_PMU_CTL, 0x400); 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x942, 0); 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci b43_phy_lcn_txrx_spur_avoidance_mode(dev, true); 6168c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x424, (u16) ~0xff00, 0x1f00); 6178c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x425, 0x590a); 6188c2ecf20Sopenharmony_ci } 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x44a, 0x44); 6218c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x44a, 0x80); 6228c2ecf20Sopenharmony_ci} 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci/* wlc_phy_chanspec_set_lcnphy */ 6258c2ecf20Sopenharmony_cistatic int b43_phy_lcn_set_channel(struct b43_wldev *dev, 6268c2ecf20Sopenharmony_ci struct ieee80211_channel *channel, 6278c2ecf20Sopenharmony_ci enum nl80211_channel_type channel_type) 6288c2ecf20Sopenharmony_ci{ 6298c2ecf20Sopenharmony_ci static const u16 sfo_cfg[14][2] = { 6308c2ecf20Sopenharmony_ci {965, 1087}, {967, 1085}, {969, 1082}, {971, 1080}, {973, 1078}, 6318c2ecf20Sopenharmony_ci {975, 1076}, {977, 1073}, {979, 1071}, {981, 1069}, {983, 1067}, 6328c2ecf20Sopenharmony_ci {985, 1065}, {987, 1063}, {989, 1060}, {994, 1055}, 6338c2ecf20Sopenharmony_ci }; 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci b43_phy_lcn_set_channel_tweaks(dev, channel->hw_value); 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x44a, 0x44); 6388c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x44a, 0x80); 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci b43_radio_2064_channel_setup(dev); 6418c2ecf20Sopenharmony_ci mdelay(1); 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci b43_phy_lcn_afe_set_unset(dev); 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x657, sfo_cfg[channel->hw_value - 1][0]); 6468c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x658, sfo_cfg[channel->hw_value - 1][1]); 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci if (channel->hw_value == 14) { 6498c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x448, ~(0x3 << 8), (2) << 8); 6508c2ecf20Sopenharmony_ci b43_phy_lcn_load_tx_iir_cck_filter(dev, 3); 6518c2ecf20Sopenharmony_ci } else { 6528c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x448, ~(0x3 << 8), (1) << 8); 6538c2ecf20Sopenharmony_ci /* brcmsmac uses filter_type 2, we follow wl with 25 */ 6548c2ecf20Sopenharmony_ci b43_phy_lcn_load_tx_iir_cck_filter(dev, 25); 6558c2ecf20Sopenharmony_ci } 6568c2ecf20Sopenharmony_ci /* brcmsmac uses filter_type 2, we follow wl with 0 */ 6578c2ecf20Sopenharmony_ci b43_phy_lcn_load_tx_iir_ofdm_filter(dev, 0); 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x4eb, ~(0x7 << 3), 0x1 << 3); 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci return 0; 6628c2ecf20Sopenharmony_ci} 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci/************************************************** 6658c2ecf20Sopenharmony_ci * Basic PHY ops. 6668c2ecf20Sopenharmony_ci **************************************************/ 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_cistatic int b43_phy_lcn_op_allocate(struct b43_wldev *dev) 6698c2ecf20Sopenharmony_ci{ 6708c2ecf20Sopenharmony_ci struct b43_phy_lcn *phy_lcn; 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci phy_lcn = kzalloc(sizeof(*phy_lcn), GFP_KERNEL); 6738c2ecf20Sopenharmony_ci if (!phy_lcn) 6748c2ecf20Sopenharmony_ci return -ENOMEM; 6758c2ecf20Sopenharmony_ci dev->phy.lcn = phy_lcn; 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_ci return 0; 6788c2ecf20Sopenharmony_ci} 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_cistatic void b43_phy_lcn_op_free(struct b43_wldev *dev) 6818c2ecf20Sopenharmony_ci{ 6828c2ecf20Sopenharmony_ci struct b43_phy *phy = &dev->phy; 6838c2ecf20Sopenharmony_ci struct b43_phy_lcn *phy_lcn = phy->lcn; 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci kfree(phy_lcn); 6868c2ecf20Sopenharmony_ci phy->lcn = NULL; 6878c2ecf20Sopenharmony_ci} 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_cistatic void b43_phy_lcn_op_prepare_structs(struct b43_wldev *dev) 6908c2ecf20Sopenharmony_ci{ 6918c2ecf20Sopenharmony_ci struct b43_phy *phy = &dev->phy; 6928c2ecf20Sopenharmony_ci struct b43_phy_lcn *phy_lcn = phy->lcn; 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci memset(phy_lcn, 0, sizeof(*phy_lcn)); 6958c2ecf20Sopenharmony_ci} 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_ci/* wlc_phy_init_lcnphy */ 6988c2ecf20Sopenharmony_cistatic int b43_phy_lcn_op_init(struct b43_wldev *dev) 6998c2ecf20Sopenharmony_ci{ 7008c2ecf20Sopenharmony_ci struct bcma_drv_cc *cc = &dev->dev->bdev->bus->drv_cc; 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x44a, 0x80); 7038c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x44a, 0x7f); 7048c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x6d1, 0x80); 7058c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x6d0, 0x7); 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci b43_phy_lcn_afe_set_unset(dev); 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x60a, 0xa0); 7108c2ecf20Sopenharmony_ci b43_phy_write(dev, 0x46a, 0x19); 7118c2ecf20Sopenharmony_ci b43_phy_maskset(dev, 0x663, 0xFF00, 0x64); 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci b43_phy_lcn_tables_init(dev); 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci b43_phy_lcn_rev0_baseband_init(dev); 7168c2ecf20Sopenharmony_ci b43_phy_lcn_bu_tweaks(dev); 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci if (dev->phy.radio_ver == 0x2064) 7198c2ecf20Sopenharmony_ci b43_radio_2064_init(dev); 7208c2ecf20Sopenharmony_ci else 7218c2ecf20Sopenharmony_ci B43_WARN_ON(1); 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) 7248c2ecf20Sopenharmony_ci b43_phy_lcn_tx_pwr_ctl_init(dev); 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci b43_switch_channel(dev, dev->phy.channel); 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci bcma_chipco_regctl_maskset(cc, 0, 0xf, 0x9); 7298c2ecf20Sopenharmony_ci bcma_chipco_chipctl_maskset(cc, 0, 0, 0x03cddddd); 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci /* TODO */ 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci b43_phy_set(dev, 0x448, 0x4000); 7348c2ecf20Sopenharmony_ci udelay(100); 7358c2ecf20Sopenharmony_ci b43_phy_mask(dev, 0x448, ~0x4000); 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci /* TODO */ 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci return 0; 7408c2ecf20Sopenharmony_ci} 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_cistatic void b43_phy_lcn_op_software_rfkill(struct b43_wldev *dev, 7438c2ecf20Sopenharmony_ci bool blocked) 7448c2ecf20Sopenharmony_ci{ 7458c2ecf20Sopenharmony_ci if (b43_read32(dev, B43_MMIO_MACCTL) & B43_MACCTL_ENABLED) 7468c2ecf20Sopenharmony_ci b43err(dev->wl, "MAC not suspended\n"); 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci if (blocked) { 7498c2ecf20Sopenharmony_ci b43_phy_mask(dev, B43_PHY_LCN_RF_CTL2, ~0x7c00); 7508c2ecf20Sopenharmony_ci b43_phy_set(dev, B43_PHY_LCN_RF_CTL1, 0x1f00); 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci b43_phy_mask(dev, B43_PHY_LCN_RF_CTL5, ~0x7f00); 7538c2ecf20Sopenharmony_ci b43_phy_mask(dev, B43_PHY_LCN_RF_CTL4, ~0x2); 7548c2ecf20Sopenharmony_ci b43_phy_set(dev, B43_PHY_LCN_RF_CTL3, 0x808); 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci b43_phy_mask(dev, B43_PHY_LCN_RF_CTL7, ~0x8); 7578c2ecf20Sopenharmony_ci b43_phy_set(dev, B43_PHY_LCN_RF_CTL6, 0x8); 7588c2ecf20Sopenharmony_ci } else { 7598c2ecf20Sopenharmony_ci b43_phy_mask(dev, B43_PHY_LCN_RF_CTL1, ~0x1f00); 7608c2ecf20Sopenharmony_ci b43_phy_mask(dev, B43_PHY_LCN_RF_CTL3, ~0x808); 7618c2ecf20Sopenharmony_ci b43_phy_mask(dev, B43_PHY_LCN_RF_CTL6, ~0x8); 7628c2ecf20Sopenharmony_ci } 7638c2ecf20Sopenharmony_ci} 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_cistatic void b43_phy_lcn_op_switch_analog(struct b43_wldev *dev, bool on) 7668c2ecf20Sopenharmony_ci{ 7678c2ecf20Sopenharmony_ci if (on) { 7688c2ecf20Sopenharmony_ci b43_phy_mask(dev, B43_PHY_LCN_AFE_CTL1, ~0x7); 7698c2ecf20Sopenharmony_ci } else { 7708c2ecf20Sopenharmony_ci b43_phy_set(dev, B43_PHY_LCN_AFE_CTL2, 0x7); 7718c2ecf20Sopenharmony_ci b43_phy_set(dev, B43_PHY_LCN_AFE_CTL1, 0x7); 7728c2ecf20Sopenharmony_ci } 7738c2ecf20Sopenharmony_ci} 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_cistatic int b43_phy_lcn_op_switch_channel(struct b43_wldev *dev, 7768c2ecf20Sopenharmony_ci unsigned int new_channel) 7778c2ecf20Sopenharmony_ci{ 7788c2ecf20Sopenharmony_ci struct ieee80211_channel *channel = dev->wl->hw->conf.chandef.chan; 7798c2ecf20Sopenharmony_ci enum nl80211_channel_type channel_type = 7808c2ecf20Sopenharmony_ci cfg80211_get_chandef_type(&dev->wl->hw->conf.chandef); 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) { 7838c2ecf20Sopenharmony_ci if ((new_channel < 1) || (new_channel > 14)) 7848c2ecf20Sopenharmony_ci return -EINVAL; 7858c2ecf20Sopenharmony_ci } else { 7868c2ecf20Sopenharmony_ci return -EINVAL; 7878c2ecf20Sopenharmony_ci } 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci return b43_phy_lcn_set_channel(dev, channel, channel_type); 7908c2ecf20Sopenharmony_ci} 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_cistatic unsigned int b43_phy_lcn_op_get_default_chan(struct b43_wldev *dev) 7938c2ecf20Sopenharmony_ci{ 7948c2ecf20Sopenharmony_ci if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) 7958c2ecf20Sopenharmony_ci return 1; 7968c2ecf20Sopenharmony_ci return 36; 7978c2ecf20Sopenharmony_ci} 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_cistatic enum b43_txpwr_result 8008c2ecf20Sopenharmony_cib43_phy_lcn_op_recalc_txpower(struct b43_wldev *dev, bool ignore_tssi) 8018c2ecf20Sopenharmony_ci{ 8028c2ecf20Sopenharmony_ci return B43_TXPWR_RES_DONE; 8038c2ecf20Sopenharmony_ci} 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_cistatic void b43_phy_lcn_op_adjust_txpower(struct b43_wldev *dev) 8068c2ecf20Sopenharmony_ci{ 8078c2ecf20Sopenharmony_ci} 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci/************************************************** 8108c2ecf20Sopenharmony_ci * R/W ops. 8118c2ecf20Sopenharmony_ci **************************************************/ 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_cistatic void b43_phy_lcn_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask, 8148c2ecf20Sopenharmony_ci u16 set) 8158c2ecf20Sopenharmony_ci{ 8168c2ecf20Sopenharmony_ci b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg); 8178c2ecf20Sopenharmony_ci b43_write16(dev, B43_MMIO_PHY_DATA, 8188c2ecf20Sopenharmony_ci (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set); 8198c2ecf20Sopenharmony_ci} 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_cistatic u16 b43_phy_lcn_op_radio_read(struct b43_wldev *dev, u16 reg) 8228c2ecf20Sopenharmony_ci{ 8238c2ecf20Sopenharmony_ci /* LCN-PHY needs 0x200 for read access */ 8248c2ecf20Sopenharmony_ci reg |= 0x200; 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci b43_write16f(dev, B43_MMIO_RADIO24_CONTROL, reg); 8278c2ecf20Sopenharmony_ci return b43_read16(dev, B43_MMIO_RADIO24_DATA); 8288c2ecf20Sopenharmony_ci} 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_cistatic void b43_phy_lcn_op_radio_write(struct b43_wldev *dev, u16 reg, 8318c2ecf20Sopenharmony_ci u16 value) 8328c2ecf20Sopenharmony_ci{ 8338c2ecf20Sopenharmony_ci b43_write16f(dev, B43_MMIO_RADIO24_CONTROL, reg); 8348c2ecf20Sopenharmony_ci b43_write16(dev, B43_MMIO_RADIO24_DATA, value); 8358c2ecf20Sopenharmony_ci} 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci/************************************************** 8388c2ecf20Sopenharmony_ci * PHY ops struct. 8398c2ecf20Sopenharmony_ci **************************************************/ 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ciconst struct b43_phy_operations b43_phyops_lcn = { 8428c2ecf20Sopenharmony_ci .allocate = b43_phy_lcn_op_allocate, 8438c2ecf20Sopenharmony_ci .free = b43_phy_lcn_op_free, 8448c2ecf20Sopenharmony_ci .prepare_structs = b43_phy_lcn_op_prepare_structs, 8458c2ecf20Sopenharmony_ci .init = b43_phy_lcn_op_init, 8468c2ecf20Sopenharmony_ci .phy_maskset = b43_phy_lcn_op_maskset, 8478c2ecf20Sopenharmony_ci .radio_read = b43_phy_lcn_op_radio_read, 8488c2ecf20Sopenharmony_ci .radio_write = b43_phy_lcn_op_radio_write, 8498c2ecf20Sopenharmony_ci .software_rfkill = b43_phy_lcn_op_software_rfkill, 8508c2ecf20Sopenharmony_ci .switch_analog = b43_phy_lcn_op_switch_analog, 8518c2ecf20Sopenharmony_ci .switch_channel = b43_phy_lcn_op_switch_channel, 8528c2ecf20Sopenharmony_ci .get_default_chan = b43_phy_lcn_op_get_default_chan, 8538c2ecf20Sopenharmony_ci .recalc_txpower = b43_phy_lcn_op_recalc_txpower, 8548c2ecf20Sopenharmony_ci .adjust_txpower = b43_phy_lcn_op_adjust_txpower, 8558c2ecf20Sopenharmony_ci}; 856