Michael Buesch | 424047e | 2008-01-09 16:13:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Broadcom B43 wireless driver |
| 4 | IEEE 802.11n PHY support |
| 5 | |
| 6 | Copyright (c) 2008 Michael Buesch <mb@bu3sch.de> |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; see the file COPYING. If not, write to |
| 20 | the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, |
| 21 | Boston, MA 02110-1301, USA. |
| 22 | |
| 23 | */ |
| 24 | |
John W. Linville | 819d772 | 2008-01-17 16:57:10 -0500 | [diff] [blame^] | 25 | #include <linux/delay.h> |
| 26 | #include <linux/types.h> |
| 27 | |
Michael Buesch | 424047e | 2008-01-09 16:13:56 +0100 | [diff] [blame] | 28 | #include "b43.h" |
| 29 | #include "nphy.h" |
Michael Buesch | 53a6e23 | 2008-01-13 21:23:44 +0100 | [diff] [blame] | 30 | #include "tables_nphy.h" |
Michael Buesch | 424047e | 2008-01-09 16:13:56 +0100 | [diff] [blame] | 31 | |
| 32 | |
Michael Buesch | 53a6e23 | 2008-01-13 21:23:44 +0100 | [diff] [blame] | 33 | void b43_nphy_set_rxantenna(struct b43_wldev *dev, int antenna) |
| 34 | {//TODO |
| 35 | } |
| 36 | |
| 37 | void b43_nphy_xmitpower(struct b43_wldev *dev) |
| 38 | {//TODO |
| 39 | } |
| 40 | |
Michael Buesch | d159131 | 2008-01-14 00:05:57 +0100 | [diff] [blame] | 41 | static void b43_chantab_radio_upload(struct b43_wldev *dev, |
| 42 | const struct b43_nphy_channeltab_entry *e) |
| 43 | { |
| 44 | b43_radio_write16(dev, B2055_PLL_REF, e->radio_pll_ref); |
| 45 | b43_radio_write16(dev, B2055_RF_PLLMOD0, e->radio_rf_pllmod0); |
| 46 | b43_radio_write16(dev, B2055_RF_PLLMOD1, e->radio_rf_pllmod1); |
| 47 | b43_radio_write16(dev, B2055_VCO_CAPTAIL, e->radio_vco_captail); |
| 48 | b43_radio_write16(dev, B2055_VCO_CAL1, e->radio_vco_cal1); |
| 49 | b43_radio_write16(dev, B2055_VCO_CAL2, e->radio_vco_cal2); |
| 50 | b43_radio_write16(dev, B2055_PLL_LFC1, e->radio_pll_lfc1); |
| 51 | b43_radio_write16(dev, B2055_PLL_LFR1, e->radio_pll_lfr1); |
| 52 | b43_radio_write16(dev, B2055_PLL_LFC2, e->radio_pll_lfc2); |
| 53 | b43_radio_write16(dev, B2055_LGBUF_CENBUF, e->radio_lgbuf_cenbuf); |
| 54 | b43_radio_write16(dev, B2055_LGEN_TUNE1, e->radio_lgen_tune1); |
| 55 | b43_radio_write16(dev, B2055_LGEN_TUNE2, e->radio_lgen_tune2); |
| 56 | b43_radio_write16(dev, B2055_C1_LGBUF_ATUNE, e->radio_c1_lgbuf_atune); |
| 57 | b43_radio_write16(dev, B2055_C1_LGBUF_GTUNE, e->radio_c1_lgbuf_gtune); |
| 58 | b43_radio_write16(dev, B2055_C1_RX_RFR1, e->radio_c1_rx_rfr1); |
| 59 | b43_radio_write16(dev, B2055_C1_TX_PGAPADTN, e->radio_c1_tx_pgapadtn); |
| 60 | b43_radio_write16(dev, B2055_C1_TX_MXBGTRIM, e->radio_c1_tx_mxbgtrim); |
| 61 | b43_radio_write16(dev, B2055_C2_LGBUF_ATUNE, e->radio_c2_lgbuf_atune); |
| 62 | b43_radio_write16(dev, B2055_C2_LGBUF_GTUNE, e->radio_c2_lgbuf_gtune); |
| 63 | b43_radio_write16(dev, B2055_C2_RX_RFR1, e->radio_c2_rx_rfr1); |
| 64 | b43_radio_write16(dev, B2055_C2_TX_PGAPADTN, e->radio_c2_tx_pgapadtn); |
| 65 | b43_radio_write16(dev, B2055_C2_TX_MXBGTRIM, e->radio_c2_tx_mxbgtrim); |
| 66 | } |
| 67 | |
| 68 | static void b43_chantab_phy_upload(struct b43_wldev *dev, |
| 69 | const struct b43_nphy_channeltab_entry *e) |
| 70 | { |
| 71 | b43_phy_write(dev, B43_NPHY_BW1A, e->phy_bw1a); |
| 72 | b43_phy_write(dev, B43_NPHY_BW2, e->phy_bw2); |
| 73 | b43_phy_write(dev, B43_NPHY_BW3, e->phy_bw3); |
| 74 | b43_phy_write(dev, B43_NPHY_BW4, e->phy_bw4); |
| 75 | b43_phy_write(dev, B43_NPHY_BW5, e->phy_bw5); |
| 76 | b43_phy_write(dev, B43_NPHY_BW6, e->phy_bw6); |
| 77 | } |
| 78 | |
| 79 | static void b43_nphy_tx_power_fix(struct b43_wldev *dev) |
| 80 | { |
| 81 | //TODO |
| 82 | } |
| 83 | |
Michael Buesch | 53a6e23 | 2008-01-13 21:23:44 +0100 | [diff] [blame] | 84 | /* Tune the hardware to a new channel. Don't call this directly. |
| 85 | * Use b43_radio_selectchannel() */ |
Michael Buesch | d159131 | 2008-01-14 00:05:57 +0100 | [diff] [blame] | 86 | int b43_nphy_selectchannel(struct b43_wldev *dev, u8 channel) |
Michael Buesch | 53a6e23 | 2008-01-13 21:23:44 +0100 | [diff] [blame] | 87 | { |
Michael Buesch | d159131 | 2008-01-14 00:05:57 +0100 | [diff] [blame] | 88 | const struct b43_nphy_channeltab_entry *tabent; |
Michael Buesch | 53a6e23 | 2008-01-13 21:23:44 +0100 | [diff] [blame] | 89 | |
Michael Buesch | d159131 | 2008-01-14 00:05:57 +0100 | [diff] [blame] | 90 | tabent = b43_nphy_get_chantabent(dev, channel); |
| 91 | if (!tabent) |
| 92 | return -ESRCH; |
| 93 | |
| 94 | //FIXME enable/disable band select upper20 in RXCTL |
| 95 | if (0 /*FIXME 5Ghz*/) |
| 96 | b43_radio_maskset(dev, B2055_MASTER1, 0xFF8F, 0x20); |
| 97 | else |
| 98 | b43_radio_maskset(dev, B2055_MASTER1, 0xFF8F, 0x50); |
| 99 | b43_chantab_radio_upload(dev, tabent); |
| 100 | udelay(50); |
| 101 | b43_radio_write16(dev, B2055_VCO_CAL10, 5); |
| 102 | b43_radio_write16(dev, B2055_VCO_CAL10, 45); |
| 103 | b43_radio_write16(dev, B2055_VCO_CAL10, 65); |
| 104 | udelay(300); |
| 105 | if (0 /*FIXME 5Ghz*/) |
| 106 | b43_phy_set(dev, B43_NPHY_BANDCTL, B43_NPHY_BANDCTL_5GHZ); |
| 107 | else |
| 108 | b43_phy_mask(dev, B43_NPHY_BANDCTL, ~B43_NPHY_BANDCTL_5GHZ); |
| 109 | b43_chantab_phy_upload(dev, tabent); |
| 110 | b43_nphy_tx_power_fix(dev); |
| 111 | |
| 112 | return 0; |
Michael Buesch | 53a6e23 | 2008-01-13 21:23:44 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static void b43_radio_init2055_pre(struct b43_wldev *dev) |
| 116 | { |
| 117 | b43_phy_mask(dev, B43_NPHY_RFCTL_CMD, |
| 118 | ~B43_NPHY_RFCTL_CMD_PORFORCE); |
| 119 | b43_phy_set(dev, B43_NPHY_RFCTL_CMD, |
| 120 | B43_NPHY_RFCTL_CMD_CHIP0PU | |
| 121 | B43_NPHY_RFCTL_CMD_OEPORFORCE); |
| 122 | b43_phy_set(dev, B43_NPHY_RFCTL_CMD, |
| 123 | B43_NPHY_RFCTL_CMD_PORFORCE); |
| 124 | } |
| 125 | |
| 126 | static void b43_radio_init2055_post(struct b43_wldev *dev) |
| 127 | { |
| 128 | struct ssb_sprom *sprom = &(dev->dev->bus->sprom); |
| 129 | struct ssb_boardinfo *binfo = &(dev->dev->bus->boardinfo); |
| 130 | int i; |
| 131 | u16 val; |
| 132 | |
| 133 | b43_radio_mask(dev, B2055_MASTER1, 0xFFF3); |
| 134 | msleep(1); |
| 135 | if ((sprom->revision != 4) || !(sprom->boardflags_hi & 0x0002)) { |
| 136 | if ((binfo->vendor != PCI_VENDOR_ID_BROADCOM) || |
| 137 | (binfo->type != 0x46D) || |
| 138 | (binfo->rev < 0x41)) { |
| 139 | b43_radio_mask(dev, B2055_C1_RX_BB_REG, 0x7F); |
| 140 | b43_radio_mask(dev, B2055_C1_RX_BB_REG, 0x7F); |
| 141 | msleep(1); |
| 142 | } |
| 143 | } |
| 144 | b43_radio_maskset(dev, B2055_RRCCAL_NOPTSEL, 0x3F, 0x2C); |
| 145 | msleep(1); |
| 146 | b43_radio_write16(dev, B2055_CAL_MISC, 0x3C); |
| 147 | msleep(1); |
| 148 | b43_radio_mask(dev, B2055_CAL_MISC, 0xFFBE); |
| 149 | msleep(1); |
| 150 | b43_radio_set(dev, B2055_CAL_LPOCTL, 0x80); |
| 151 | msleep(1); |
| 152 | b43_radio_set(dev, B2055_CAL_MISC, 0x1); |
| 153 | msleep(1); |
| 154 | b43_radio_set(dev, B2055_CAL_MISC, 0x40); |
| 155 | msleep(1); |
| 156 | for (i = 0; i < 100; i++) { |
| 157 | val = b43_radio_read16(dev, B2055_CAL_COUT2); |
| 158 | if (val & 0x80) |
| 159 | break; |
| 160 | udelay(10); |
| 161 | } |
| 162 | msleep(1); |
| 163 | b43_radio_mask(dev, B2055_CAL_LPOCTL, 0xFF7F); |
| 164 | msleep(1); |
| 165 | b43_radio_selectchannel(dev, dev->phy.channel, 0); |
| 166 | b43_radio_write16(dev, B2055_C1_RX_BB_LPF, 0x9); |
| 167 | b43_radio_write16(dev, B2055_C2_RX_BB_LPF, 0x9); |
| 168 | b43_radio_write16(dev, B2055_C1_RX_BB_MIDACHP, 0x83); |
| 169 | b43_radio_write16(dev, B2055_C2_RX_BB_MIDACHP, 0x83); |
| 170 | } |
| 171 | |
| 172 | /* Initialize a Broadcom 2055 N-radio */ |
| 173 | static void b43_radio_init2055(struct b43_wldev *dev) |
| 174 | { |
| 175 | b43_radio_init2055_pre(dev); |
| 176 | if (b43_status(dev) < B43_STAT_INITIALIZED) |
| 177 | b2055_upload_inittab(dev, 0, 1); |
| 178 | else |
| 179 | b2055_upload_inittab(dev, 0/*FIXME on 5ghz band*/, 0); |
| 180 | b43_radio_init2055_post(dev); |
| 181 | } |
| 182 | |
| 183 | void b43_nphy_radio_turn_on(struct b43_wldev *dev) |
| 184 | { |
| 185 | b43_radio_init2055(dev); |
| 186 | } |
| 187 | |
| 188 | void b43_nphy_radio_turn_off(struct b43_wldev *dev) |
| 189 | { |
| 190 | b43_phy_mask(dev, B43_NPHY_RFCTL_CMD, |
| 191 | ~B43_NPHY_RFCTL_CMD_EN); |
| 192 | } |
| 193 | |
Michael Buesch | 424047e | 2008-01-09 16:13:56 +0100 | [diff] [blame] | 194 | int b43_phy_initn(struct b43_wldev *dev) |
| 195 | { |
| 196 | b43err(dev->wl, "IEEE 802.11n devices are not supported, yet.\n"); |
| 197 | |
Michael Buesch | 53a6e23 | 2008-01-13 21:23:44 +0100 | [diff] [blame] | 198 | return 0; |
Michael Buesch | 424047e | 2008-01-09 16:13:56 +0100 | [diff] [blame] | 199 | } |